unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] GitCatFile: use offset for read instead of appending
@ 2015-08-23  2:40 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-23  2:40 UTC (permalink / raw)
  To: meta

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(-)

diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm
index 8bc6a23..9bffce2 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";
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-23  2:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-23  2:40 [PATCH] GitCatFile: use offset for read instead of appending Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).