]> Savannah Git Hosting - gnulib.git/commitdiff
csharpcomp: Reduce number of read() system calls.
authorBruno Haible <bruno@clisp.org>
Tue, 25 Feb 2025 08:04:45 +0000 (09:04 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 25 Feb 2025 08:20:17 +0000 (09:20 +0100)
* lib/csharpcomp.c: Include <stddef.h>.
(compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one.

ChangeLog
lib/csharpcomp.c

index af7413ee5e1b8979e9448da66f9f547d311b5b1c..4ece515f20961a058170f6a38df84a984372f43b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-02-25  Bruno Haible  <bruno@clisp.org>
+
+       csharpcomp: Reduce number of read() system calls.
+       * lib/csharpcomp.c: Include <stddef.h>.
+       (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one.
+
 2025-02-25  Bruno Haible  <bruno@clisp.org>
 
        vc-mtime: Reduce number of read() system calls.
index ad74604dd854c8931bc22f602aaee9581d092792..5b6c9684d97e57692440dca278f3d69c6839973c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -311,11 +312,17 @@ compile_csharp_using_dotnet (const char * const *sources,
             {
               /* Read the subprocess output, and test whether it is
                  non-empty.  */
-              size_t count = 0;
-              char c;
+              ptrdiff_t count = 0;
 
-              while (safe_read (fd[0], &c, 1) > 0)
-                count++;
+              for (;;)
+                {
+                  char buf[1024];
+                  ptrdiff_t n = safe_read (fd[0], buf, sizeof (buf));
+                  if (n > 0)
+                    count += n;
+                  else
+                    break;
+                }
 
               close (fd[0]);