From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1B9291FAC6 for ; Sun, 23 Aug 2015 02:40:20 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] GitCatFile: use offset for read instead of appending Date: Sun, 23 Aug 2015 02:40:19 +0000 Message-Id: <1440297620-2892-1-git-send-email-e@80x24.org> List-Id: 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