about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-03 09:11:00 +0000
committerEric Wong <e@80x24.org>2019-06-10 05:05:15 +0000
commit6fa2b29fcd0477d126ebb7db7f97b334f74bbcbc (patch)
tree898548943442cd3b9e0ec8ebf986052b2b2fd2e9 /lib
parent42bb1574bf35a18f037d4ca8b0e6696192d301df (diff)
downloadpublic-inbox-6fa2b29fcd0477d126ebb7db7f97b334f74bbcbc.tar.gz
Stop importing unused constants, and favor integer comparisons
of `$!' over `$!{EFOO}' hash lookups.  Integer comparisons are
slightly faster, even:

Benchmark: timing 30 iterations of cmp_eq, cmp_ne, hash_hit, hash_miss...
    cmp_eq:  1 wallclock secs ( 1.61 usr +  0.00 sys =  1.61 CPU) @ 18.63/s (n=30)
    cmp_ne:  2 wallclock secs ( 1.57 usr +  0.00 sys =  1.57 CPU) @ 19.11/s (n=30)
  hash_hit:  4 wallclock secs ( 3.85 usr +  0.00 sys =  3.85 CPU) @  7.79/s (n=30)
 hash_miss:  4 wallclock secs ( 3.74 usr +  0.00 sys =  3.74 CPU) @  8.02/s (n=30)

	#!/usr/bin/perl -w
	use Benchmark qw(:all);
	use Errno qw(EAGAIN EINTR);
	my ($r, $w);
	pipe($r, $w) or die 'pipe';
	require IO::Handle;
	$r->blocking(0);
	my $buf;
	my $n = 30000;
	timethese(30, {
		hash_hit => sub {
			sysread($r, $buf, 1);
			for (0..$n) {
				next if $!{EAGAIN};
				die 'FAIL';
			}
		}
		,
		'cmp_eq' => sub {
			sysread($r, $buf, 1);
			for (0..$n) {
				next if $! == EAGAIN;
				die 'FAIL';
			}
		},
		hash_miss => sub {
			sysread($r, $buf, 1);
			for (0..$n) {
				die 'FAIL' if $!{EINTR};
			}
		},
		'cmp_ne' => sub {
			sysread($r, $buf, 1);
			for (0..$n) {
				die 'FAIL' if $! == EINTR;
			}
		},
	});
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/DS.pm7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 172a9f52..39f1922f 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -33,8 +33,7 @@ use fields ('sock',              # underlying socket
             'event_watch',       # bitmask of events the client is interested in (POLLIN,OUT,etc.)
             );
 
-use Errno  qw(EINPROGRESS EWOULDBLOCK EISCONN ENOTSOCK
-              EPIPE EAGAIN EBADF ECONNRESET ENOPROTOOPT);
+use Errno  qw(EPIPE EAGAIN ECONNRESET EINVAL);
 use Carp   qw(croak confess);
 
 use constant DebugLevel => 0;
@@ -462,7 +461,7 @@ sub new {
         }
 retry:
         if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
-            if ($!{EINVAL} && ($ev & $EPOLLEXCLUSIVE)) {
+            if ($! == EINVAL && ($ev & $EPOLLEXCLUSIVE)) {
                 $EPOLLEXCLUSIVE = 0; # old kernel
                 $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP;
                 goto retry;
@@ -730,7 +729,7 @@ sub read {
     my $res = sysread($sock, $buf, $req_bytes, 0);
     DebugLevel >= 2 && $self->debugmsg("sysread = %d; \$! = %d", $res, $!);
 
-    if (! $res && $! != EWOULDBLOCK) {
+    if (! $res && $! != EAGAIN) {
         # catches 0=conn closed or undef=error
         DebugLevel >= 2 && $self->debugmsg("Fd \#%d read hit the end of the road.", $self->{fd});
         return undef;