From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9389B1F454 for ; Wed, 12 Apr 2023 00:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1681258382; bh=5auVh+BsVFVqOca0l66fdvcqohcSfyGWnN1G75DEnNU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cd1tBsjqHq3tsm89wjvOiEQiFhNxIZJHz/REtIJBliC3gjT1856ikqsIzfvFjzOgt laiMZAl90lxMkCune+7AdOALoS6j5lt4sSJsShg8JhvV4Vyuw0jf26tjrm2+fiJunk M2E81gSf3THh92VwSdDO0Tt6gG/FTIezpzg9zZFI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/5] git: cat_async_step: reduce batch-command info checks Date: Wed, 12 Apr 2023 00:12:58 +0000 Message-Id: <20230412001302.685421-2-e@80x24.org> In-Reply-To: <20230412001302.685421-1-e@80x24.org> References: <20230412001302.685421-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This improves readability for me. Instead of checking for `info ' requests of `--batch-command' in multiple places of every common branch, do it once per-call and stash its result. We'll also avoid storing `$bc' for now since the only other check is in a cold path. --- lib/PublicInbox/Git.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index f153237b..cc337e5d 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -262,20 +262,19 @@ sub cat_async_step ($$) { my $head = my_readline($self->{in}, $rbuf); my $cmd = ref($req) ? $$req : $req; # ->fail may be called via Gcf2Client.pm - my $bc = $self->{-bc}; + my $info = $self->{-bc} && substr($cmd, 0, 5) eq 'info '; if ($head =~ /^([0-9a-f]{40,}) (\S+) ([0-9]+)$/) { ($oid, $type, $size) = ($1, $2, $3 + 0); - unless ($bc && $cmd =~ /\Ainfo /) { # --batch-command + unless ($info) { # --batch-command $bref = my_read($self->{in}, $rbuf, $size + 1) or $self->fail(defined($bref) ? 'read EOF' : "read: $!"); chop($$bref) eq "\n" or $self->fail('LF missing after blob'); } - } elsif ($bc && $cmd =~ /\Ainfo / && - $head =~ / (missing|ambiguous)\n/) { + } elsif ($info && $head =~ / (missing|ambiguous)\n/) { $type = $1; - $oid = substr($cmd, 5); + $oid = substr($cmd, 5); # remove 'info ' } elsif ($head =~ s/ missing\n//s) { $oid = $head; # ref($req) indicates it's already been retried @@ -286,7 +285,7 @@ sub cat_async_step ($$) { $type = 'missing'; if ($oid eq '') { $oid = $cmd; - $oid =~ s/\A(?:contents|info) // if $bc; + $oid =~ s/\A(?:contents|info) // if $self->{-bc}; } } else { my $err = $! ? " ($!)" : ''; @@ -294,7 +293,7 @@ sub cat_async_step ($$) { } $self->{rbuf} = $rbuf if $$rbuf ne ''; splice(@$inflight, 0, 3); # don't retry $cb on ->fail - if ($bc && $cmd =~ /\Ainfo /) { + if ($info) { eval { $cb->($oid, $type, $size, $arg, $self) }; async_err($self, $req, $oid, $@, 'check') if $@; } else {