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

ChangeLog
lib/vc-mtime.c

index dfea4e0e6e0ee9f94085bf48705147d3cd6b8cfd..af7413ee5e1b8979e9448da66f9f547d311b5b1c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-02-25  Bruno Haible  <bruno@clisp.org>
+
+       vc-mtime: Reduce number of read() system calls.
+       * lib/vc-mtime.c: Include <stddef.h>.
+       (git_vc_controlled): Read bytes into a buffer, not one-by-one.
+
 2025-02-25  Bruno Haible  <bruno@clisp.org>
 
        vc-mtime: Improve comment.
index 0e609033f66df2a43062ff77010849e4c84c5083..f80bd77b690368e4f78ca47042da9ba2f43d4a28 100644 (file)
@@ -21,6 +21,7 @@
 /* Specification.  */
 #include "vc-mtime.h"
 
+#include <stddef.h>
 #include <stdlib.h>
 #include <unistd.h>
 
@@ -56,11 +57,17 @@ git_vc_controlled (const char *filename)
     return false;
 
   /* 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]);