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 460CB1FA01 for ; Mon, 22 Mar 2021 07:54:03 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/8] lei: simplify workers_start and callers Date: Mon, 22 Mar 2021 07:53:58 +0000 Message-Id: <20210322075402.27834-5-e@80x24.org> In-Reply-To: <20210322075402.27834-1-e@80x24.org> References: <20210322075402.27834-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Since workers_start is in the common PublicInbox::LEI package, we can just use \&METHOD_NAME instead of relying on UNIVERSAL->can to avoid a method dispatch. Most of our worker code can just use lei->dclose, so default to doing that unless it's been overridden. --- lib/PublicInbox/LEI.pm | 11 ++++++----- lib/PublicInbox/LeiConvert.pm | 4 +--- lib/PublicInbox/LeiP2q.pm | 4 +--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 0bd52a46..1e720b89 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -481,12 +481,13 @@ sub lei_atfork_child { sub workers_start { my ($lei, $wq, $ident, $jobs, $ops) = @_; $ops = { - '!' => [ $lei->can('fail_handler'), $lei ], - '|' => [ $lei->can('sigpipe_handler'), $lei ], - 'x_it' => [ $lei->can('x_it'), $lei ], - 'child_error' => [ $lei->can('child_error'), $lei ], - %$ops + '!' => [ \&fail_handler, $lei ], + '|' => [ \&sigpipe_handler, $lei ], + 'x_it' => [ \&x_it, $lei ], + 'child_error' => [ \&child_error, $lei ], + ($ops ? %$ops : ()), }; + $ops->{''} //= [ \&dclose, $lei ]; require PublicInbox::PktOp; ($lei->{pkt_op_c}, $lei->{pkt_op_p}) = PublicInbox::PktOp->pair($ops); $wq->wq_workers_start($ident, $jobs, $lei->oldset, { lei => $lei }); diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index 0aa13229..8685c194 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -87,9 +87,7 @@ sub lei_convert { # the main "lei convert" method $lei->fail("output not specified or is not a mail destination"); $lei->{opt}->{augment} = 1 unless $ovv->{dst} eq '/dev/stdout'; $self->prepare_inputs($lei, \@inputs) or return; - my $op = $lei->workers_start($self, 'lei_convert', 1, { - '' => [ $lei->can('dclose'), $lei ] - }); + my $op = $lei->workers_start($self, 'lei_convert', 1); $self->wq_io_do('do_convert', []); $self->wq_close(1); while ($op && $op->{sock}) { $op->event_step } diff --git a/lib/PublicInbox/LeiP2q.pm b/lib/PublicInbox/LeiP2q.pm index 302d7864..4abe1345 100644 --- a/lib/PublicInbox/LeiP2q.pm +++ b/lib/PublicInbox/LeiP2q.pm @@ -182,9 +182,7 @@ sub lei_p2q { # the "lei patch-to-query" entry point } else { $self->{input} = $input; } - my $op = $lei->workers_start($self, 'lei patch2query', 1, { - '' => [ $lei->{p2q_done} // $lei->can('dclose'), $lei ] - }); + my $op = $lei->workers_start($self, 'lei patch2query', 1); $self->wq_io_do('do_p2q', []); $self->wq_close(1); while ($op && $op->{sock}) { $op->event_step }