From: Eric Wong Date: Sun, 23 Aug 2015 02:40:19 +0000 (+0000) Subject: GitCatFile: use offset for read instead of appending X-Git-Tag: v1.0.0~996 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fef5b14a9c397eeece31c54c8f0d0c90a3ad2a6;p=thirdparty%2Fpublic-inbox.git GitCatFile: use offset for read instead of appending 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. --- diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm index 8bc6a238d..9bffce2aa 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";