From: Bruno Haible Date: Tue, 25 Feb 2025 08:04:45 +0000 (+0100) Subject: csharpcomp: Reduce number of read() system calls. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f703b5434b1eb02c483f631fe23368130ebc3e07;p=gnulib.git csharpcomp: Reduce number of read() system calls. * lib/csharpcomp.c: Include . (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. --- diff --git a/ChangeLog b/ChangeLog index af7413ee5e..4ece515f20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-02-25 Bruno Haible + + csharpcomp: Reduce number of read() system calls. + * lib/csharpcomp.c: Include . + (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. + 2025-02-25 Bruno Haible vc-mtime: Reduce number of read() system calls. diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c index ad74604dd8..5b6c9684d9 100644 --- a/lib/csharpcomp.c +++ b/lib/csharpcomp.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -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]);