From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] GitCatFile: use offset for read instead of appending
Date: Sun, 23 Aug 2015 02:40:19 +0000 [thread overview]
Message-ID: <1440297620-2892-1-git-send-email-e@80x24.org> (raw)
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
reply other threads:[~2015-08-23 2:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440297620-2892-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).