about summary refs log tree commit homepage
path: root/lib/PublicInbox/DS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-24 02:52:07 +0000
committerEric Wong <e@80x24.org>2019-06-24 05:26:25 +0000
commitddba176a763dd7f36e3aa53b87907c6226207efa (patch)
tree091b73e1de3fa79a04918a28ca2210e4b3e29dfa /lib/PublicInbox/DS.pm
parent8c8b5c28b20b4d8ceee89312b1cc9e4602a7beb3 (diff)
downloadpublic-inbox-ddba176a763dd7f36e3aa53b87907c6226207efa.tar.gz
Since Perl 5.10+, "fields" makes a restricted hash; not a
compile-time-defined array (struct) with fixed offsets as
it did in Perl <= 5.8.

Thus in-use fields cost memory, and since the write buffer
offset is rarely needed; stop relying on it.
Diffstat (limited to 'lib/PublicInbox/DS.pm')
-rw-r--r--lib/PublicInbox/DS.pm13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 26c5251b..154fd4dd 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -403,7 +403,6 @@ sub new {
         unless $sock && $fd;
 
     $self->{wbuf} = [];
-    $self->{wbuf_off} = 0;
 
     my $ev = $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
 
@@ -501,7 +500,7 @@ sub write {
     # now-dead object does its second write.  that is this case.  we
     # just lie and say it worked.  it'll be dead soon and won't be
     # hurt by this lie.
-    return 1 unless $self->{sock};
+    my $sock = $self->{sock} or return 1;
 
     my $bref;
 
@@ -548,9 +547,9 @@ sub write {
             die "Write error: $@ <$bref>";
         }
 
-        my $to_write = $len - $self->{wbuf_off};
-        my $written = syswrite($self->{sock}, $$bref, $to_write,
-                               $self->{wbuf_off});
+        my $off = $self->{wbuf_off} // 0;
+        my $to_write = $len - $off;
+        my $written = syswrite($sock, $$bref, $to_write, $off);
 
         if (! defined $written) {
             if ($! == EAGAIN) {
@@ -570,11 +569,11 @@ sub write {
             }
             # since connection has stuff to write, it should now be
             # interested in pending writes:
-            $self->{wbuf_off} += $written;
+            $self->{wbuf_off} = $off + $written;
             $self->watch_write(1);
             return 0;
         } elsif ($written == $to_write) {
-            $self->{wbuf_off} = 0;
+            delete $self->{wbuf_off};
             $self->watch_write(0);
 
             # this was our only write, so we can return immediately