about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-08-23 02:40:19 +0000
committerEric Wong <e@80x24.org>2015-08-23 02:40:39 +0000
commit8fef5b14a9c397eeece31c54c8f0d0c90a3ad2a6 (patch)
tree4ab47da1e013d50480e4ed3b9b08b1ecf34584e6
parent26fdec5d23301d7e0e8b957ec8ad5287c9e9b7f4 (diff)
downloadpublic-inbox-8fef5b14a9c397eeece31c54c8f0d0c90a3ad2a6.tar.gz
There is no need to perform string appends when the
"read" and "sysread" functions take an offset argument
to append to the given buffer.

This avoid needless string creation.
-rw-r--r--lib/PublicInbox/GitCatFile.pm10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index 8bc6a238..9bffce2a 100644
--- a/lib/PublicInbox/GitCatFile.pm
+++ b/lib/PublicInbox/GitCatFile.pm
@@ -68,17 +68,17 @@ sub cat_file {
 
         my $size = $1;
         my $bytes_left = $size;
-        my $buf;
+        my $offset = 0;
         my $rv = '';
 
         while ($bytes_left) {
-                my $read = read($in, $buf, $bytes_left);
-                defined($read) or die "read pipe failed: $!\n";
-                $rv .= $buf;
+                my $read = read($in, $rv, $bytes_left, $offset);
+                defined($read) or die "sysread pipe failed: $!\n";
                 $bytes_left -= $read;
+                $offset += $read;
         }
 
-        my $read = read($in, $buf, 1);
+        my $read = read($in, my $buf, 1);
         defined($read) or die "read pipe failed: $!\n";
         if ($read != 1 || $buf ne "\n") {
                 die "newline missing after blob\n";