From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 10A3E1FB0B for ; Mon, 23 Nov 2020 07:06:04 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/12] *search: simplify retry_reopen users Date: Mon, 23 Nov 2020 07:06:02 +0000 Message-Id: <20201123070602.9698-13-e@80x24.org> In-Reply-To: <20201123070602.9698-1-e@80x24.org> References: <20201123070602.9698-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Every callback uses `$self', and creating short-lived array references is not necessary when it's just as easy to copy the array in Perl (unlike C). --- lib/PublicInbox/MiscSearch.pm | 8 ++++---- lib/PublicInbox/Search.pm | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/MiscSearch.pm b/lib/PublicInbox/MiscSearch.pm index 5a44d751..48ef6914 100644 --- a/lib/PublicInbox/MiscSearch.pm +++ b/lib/PublicInbox/MiscSearch.pm @@ -50,7 +50,7 @@ sub mi_qp_new ($) { } sub misc_enquire_once { # retry_reopen callback - my ($self, $qr, $opt) = @{$_[0]}; + my ($self, $qr, $opt) = @_; my $eq = $PublicInbox::Search::X{Enquire}->new($self->{xdb}); $eq->set_query($qr); my $desc = !$opt->{asc}; @@ -73,11 +73,11 @@ sub mset { $qs = 'type:inbox' if $qs eq ''; my $qr = $qp->parse_query($qs, $PublicInbox::Search::QP_FLAGS); $opt->{relevance} = 1 unless exists $opt->{relevance}; - retry_reopen($self, \&misc_enquire_once, [ $self, $qr, $opt ]); + retry_reopen($self, \&misc_enquire_once, $qr, $opt); } sub ibx_data_once { - my ($self, $ibx) = @{$_[0]}; + my ($self, $ibx) = @_; my $xdb = $self->{xdb}; my $eidx_key = $ibx->eidx_key; # may be {inboxdir}, so private my $head = $xdb->postlist_begin('Q'.$eidx_key); @@ -92,7 +92,7 @@ sub ibx_data_once { sub inbox_data { my ($self, $ibx) = @_; - retry_reopen($self, \&ibx_data_once, [ $self, $ibx ]); + retry_reopen($self, \&ibx_data_once, $ibx); } 1; diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 05d5a133..574bc145 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -291,15 +291,15 @@ sub mset { } sub retry_reopen { - my ($self, $cb, $arg) = @_; + my ($self, $cb, @arg) = @_; for my $i (1..10) { if (wantarray) { my @ret; - eval { @ret = $cb->($arg) }; + eval { @ret = $cb->($self, @arg) }; return @ret unless $@; } else { my $ret; - eval { $ret = $cb->($arg) }; + eval { $ret = $cb->($self, @arg) }; return $ret unless $@; } # Exception: The revision being read has been discarded - @@ -319,7 +319,7 @@ sub retry_reopen { sub _do_enquire { my ($self, $query, $opts) = @_; - retry_reopen($self, \&_enquire_once, [ $self, $query, $opts ]); + retry_reopen($self, \&_enquire_once, $query, $opts); } # returns true if all docs have the THREADID value @@ -329,7 +329,7 @@ sub has_threadid ($) { } sub _enquire_once { # retry_reopen callback - my ($self, $query, $opts) = @{$_[0]}; + my ($self, $query, $opts) = @_; my $xdb = xdb($self); my $enquire = $X{Enquire}->new($xdb); $enquire->set_query($query);