Skip to content

Commit

Permalink
csharpcomp: Reduce number of read() system calls.
Browse files Browse the repository at this point in the history
* lib/csharpcomp.c: Include <stddef.h>.
(compile_csharp_using_dotnet): Read bytes into a buffer, not one-by-one.
  • Loading branch information
bhaible committed Feb 25, 2025
1 parent 60cd348 commit f703b54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2025-02-25 Bruno Haible <[email protected]>

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 <[email protected]>

vc-mtime: Reduce number of read() system calls.
Expand Down
15 changes: 11 additions & 4 deletions lib/csharpcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <dirent.h>
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit f703b54

Please sign in to comment.