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-ASN: 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 2F2E51F4BB for ; Mon, 24 Jun 2019 02:55:34 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 25/57] http|nntp: favor "$! == EFOO" over $!{EFOO} checks Date: Mon, 24 Jun 2019 02:52:26 +0000 Message-Id: <20190624025258.25592-26-e@80x24.org> In-Reply-To: <20190624025258.25592-1-e@80x24.org> References: <20190624025258.25592-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Integer comparisions of "$!" are faster than hash lookups. See commit 6fa2b29fcd0477d126ebb7db7f97b334f74bbcbc ("ds: cleanup Errno imports and favor constant comparisons") for benchmarks. --- lib/PublicInbox/HTTP.pm | 7 +++---- lib/PublicInbox/HTTPD/Async.pm | 3 ++- lib/PublicInbox/NNTP.pm | 4 ++-- lib/PublicInbox/Qspawn.pm | 7 +++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 773d77ba..4738e156 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -27,6 +27,7 @@ use constant { CHUNK_ZEND => -3, # \r\n CHUNK_MAX_HDR => 256, }; +use Errno qw(EAGAIN); my $pipelineq = []; my $pipet; @@ -82,11 +83,9 @@ sub event_step { # called by PublicInbox::DS return rbuf_process($self); } - return $self->watch_in1 if $!{EAGAIN}; - # common for clients to break connections without warning, # would be too noisy to log here: - return $self->close; + $! == EAGAIN ? $self->watch_in1 : $self->close; } sub rbuf_process { @@ -359,7 +358,7 @@ sub write_err { sub recv_err { my ($self, $r, $len) = @_; return $self->close if (defined $r && $r == 0); - if ($!{EAGAIN}) { + if ($! == EAGAIN) { $self->{input_left} = $len; return $self->watch_in1; } diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 3eb7f75a..9cc41f17 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -11,6 +11,7 @@ use warnings; use base qw(PublicInbox::DS); use fields qw(cb cleanup); require PublicInbox::EvCleanup; +use Errno qw(EAGAIN); sub new { my ($class, $io, $cb, $cleanup) = @_; @@ -57,7 +58,7 @@ sub main_cb ($$$) { } # fall through to close below... } elsif (!defined $r) { - return restart_read($self) if $!{EAGAIN}; + return restart_read($self) if $! == EAGAIN; } # Done! Error handling will happen in $fh->close diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 98f88410..fbdf1364 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -25,6 +25,7 @@ use constant { r430 => '430 No article with that message-id', }; use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT); +use Errno qw(EAGAIN); my @OVERVIEW = qw(Subject From Date Message-ID References Xref); my $OVERVIEW_FMT = join(":\r\n", @OVERVIEW, qw(Bytes Lines)) . ":\r\n"; @@ -946,8 +947,7 @@ sub event_step { my $off = length($$rbuf); $r = sysread($self->{sock}, $$rbuf, LINE_MAX, $off); unless (defined $r) { - return $self->watch_in1 if $!{EAGAIN}; - return $self->close; + return $! == EAGAIN ? $self->watch_in1 : $self->close; } return $self->close if $r == 0; } diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index 943ee801..f2630a0f 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -29,6 +29,9 @@ use warnings; use PublicInbox::Spawn qw(popen_rd); require Plack::Util; +# n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers +use Errno qw(EAGAIN EINTR); + my $def_limiter; # declares a command to spawn (but does not spawn it). @@ -131,7 +134,7 @@ sub psgi_qx { } elsif (defined $r) { $r ? $qx->write($buf) : $end->(); } else { - return if $!{EAGAIN} || $!{EINTR}; # loop again + return if $! == EAGAIN || $! == EINTR; # loop again $end->(); } }; @@ -193,7 +196,7 @@ sub psgi_return { my $buf = ''; my $rd_hdr = sub { my $r = sysread($rpipe, $buf, 1024, length($buf)); - return if !defined($r) && ($!{EINTR} || $!{EAGAIN}); + return if !defined($r) && $! == EAGAIN || $! == EINTR; $parse_hdr->($r, \$buf); }; -- EW