user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: Re: [PATCH] git: various minor speedups
Date: Wed, 29 Apr 2020 20:33:11 +0000	[thread overview]
Message-ID: <20200429203311.GA20984@dcvr> (raw)
In-Reply-To: <20200428084858.16048-1-e@yhbt.net>

Eric Wong <e@yhbt.net> wrote:
> Best off all, there's less code :>

And even less...

> --- a/lib/PublicInbox/Git.pm
> +++ b/lib/PublicInbox/Git.pm
> @@ -125,59 +125,49 @@ sub _bidi_pipe {
>  	$self->{$in} = $in_r;
>  }
>  
> -sub read_cat_in_full ($$$) {
> -	my ($self, $in, $left) = @_;
> -	my $offset = 0;
> -	my $buf = '';
> -	while ($left > 0) {
> -		my $r = read($in, $buf, $left, $offset);
> -		defined($r) or fail($self, "read failed: $!");
> -		$r == 0 and fail($self, 'exited unexpectedly');
> -		$left -= $r;
> -		$offset += $r;
> -	}
> -	my $r = read($in, my $lf, 1);
> -	defined($r) or fail($self, "read failed: $!");
> -	fail($self, 'newline missing after blob') if ($r != 1 || $lf ne "\n");
> +sub read_cat_in_full ($$) {
> +	my ($self, $left) = @_;
> +	++$left; # for final "\n" added by git
> +	my $r = read($self->{in}, my $buf, $left) == $left or
> +		fail($self, 'short read');
> +	chop($buf) eq "\n" or fail($self, 'newline missing after blob');
>  	\$buf;
>  }

No need to save `$r', and `$len' makes a better name for
a single read() than `$left' with the new code.  Will squash
this in:

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index f1911534..057135ef 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -126,10 +126,9 @@ sub _bidi_pipe {
 }
 
 sub read_cat_in_full ($$) {
-	my ($self, $left) = @_;
-	++$left; # for final "\n" added by git
-	my $r = read($self->{in}, my $buf, $left) == $left or
-		fail($self, 'short read');
+	my ($self, $len) = @_;
+	++$len; # for final "\n" added by git
+	read($self->{in}, my $buf, $len) == $len or fail($self, 'short read');
 	chop($buf) eq "\n" or fail($self, 'newline missing after blob');
 	\$buf;
 }

      reply	other threads:[~2020-04-29 20:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28  8:48 [PATCH] git: various minor speedups Eric Wong
2020-04-29 20:33 ` Eric Wong [this message]

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: http://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=20200429203311.GA20984@dcvr \
    --to=e@yhbt.net \
    --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.
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).