From 8fef5b14a9c397eeece31c54c8f0d0c90a3ad2a6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 23 Aug 2015 02:40:19 +0000 Subject: 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. --- lib/PublicInbox/GitCatFile.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/GitCatFile.pm') 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"; -- cgit v1.2.3-24-ge0c7