* [PATCH] GitCatFile: use offset for read instead of appending
@ 2015-08-23 2:40 7% Eric Wong
0 siblings, 0 replies; 1+ results
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 [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-08-23 2:40 7% [PATCH] GitCatFile: use offset for read instead of appending Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).