diff options
author | Eric Wong <e@80x24.org> | 2015-08-23 02:40:19 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-08-23 02:40:39 +0000 |
commit | 8fef5b14a9c397eeece31c54c8f0d0c90a3ad2a6 (patch) | |
tree | 4ab47da1e013d50480e4ed3b9b08b1ecf34584e6 | |
parent | 26fdec5d23301d7e0e8b957ec8ad5287c9e9b7f4 (diff) | |
download | public-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.pm | 10 |
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"; |