]> Sergey Matveev's repositories - public-inbox.git/commitdiff
gzip_filter: ->translate can reuse zmore/zflush
authorEric Wong <e@80x24.org>
Sat, 10 Sep 2022 08:17:04 +0000 (08:17 +0000)
committerEric Wong <e@80x24.org>
Sat, 10 Sep 2022 19:50:34 +0000 (19:50 +0000)
We can work towards delaying zlib context allocations in future
commits, too.

lib/PublicInbox/GzipFilter.pm

index 75ba625ed02c9987bb5a05d67dbb7a58a090b4b1..77d570b677d6fb3c6ecdf8f4e35493c687537107 100644 (file)
@@ -100,19 +100,12 @@ sub translate ($$) {
        # allocate the zlib context lazily here, instead of in ->new.
        # Deflate contexts are memory-intensive and this object may
        # be sitting in the Qspawn limiter queue for a while.
-       my $gz = $self->{gz} //= gzip_or_die();
-       my $zbuf = delete($self->{zbuf});
+       $self->{gz} //= gzip_or_die();
        if (defined $_[1]) { # my $buf = $_[1];
-               my $err = $gz->deflate($_[1], $zbuf);
-               die "gzip->deflate: $err" if $err != Z_OK;
-               return $zbuf if length($zbuf) >= 8192;
-
-               $self->{zbuf} = $zbuf;
-               '';
+               zmore($self, $_[1]);
+               length($self->{zbuf}) >= 8192 ? delete($self->{zbuf}) : '';
        } else { # undef == EOF
-               my $err = $gz->flush($zbuf);
-               die "gzip->flush: $err" if $err != Z_OK;
-               $zbuf;
+               zflush($self);
        }
 }