]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http|nntp: favor "$! == EFOO" over $!{EFOO} checks
authorEric Wong <e@80x24.org>
Mon, 24 Jun 2019 02:52:26 +0000 (02:52 +0000)
committerEric Wong <e@80x24.org>
Mon, 24 Jun 2019 05:26:26 +0000 (05:26 +0000)
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
lib/PublicInbox/HTTPD/Async.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/Qspawn.pm

index 773d77ba00b8643eb50275fc72b2de0af10f3a3a..4738e15667a7cbda30c0ba2a4108661977b0dd02 100644 (file)
@@ -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;
        }
index 3eb7f75a4eb5932441fcf7fb2551bc528cef53bf..9cc41f179e278ae9f54780f5c97aaa1bb298a513 100644 (file)
@@ -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
index 98f884104bf5220bde442eb09b2e5fc7ea7c22e0..fbdf1364ccb80423ea3f6811668148e737f26a65 100644 (file)
@@ -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;
        }
index 943ee8017908b657b7e441f11755b7abb18f5d56..f2630a0f0109a624690edf38b849423b9b0af8dd 100644 (file)
@@ -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);
        };