From f703b5434b1eb02c483f631fe23368130ebc3e07 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 25 Feb 2025 09:04:45 +0100 Subject: [PATCH] csharpcomp: Reduce number of read() system calls. * lib/csharpcomp.c: Include . (compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one. --- ChangeLog | 6 ++++++ lib/csharpcomp.c | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) 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]); -- 2.39.5