diff options
author | Eric Wong <e@80x24.org> | 2022-09-10 08:17:04 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2022-09-10 19:50:34 +0000 |
commit | 62bd66a3e385251c127a055005c88d20f540c867 (patch) | |
tree | 54417fda8e6aa1335b6b25d9d29bc4ef3312bdc6 /lib | |
parent | 7946a7fce008989458a28641cc899c8bbd99c2c4 (diff) | |
download | public-inbox-62bd66a3e385251c127a055005c88d20f540c867.tar.gz |
gzip_filter: ->translate can reuse zmore/zflush
We can work towards delaying zlib context allocations in future commits, too.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PublicInbox/GzipFilter.pm | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/PublicInbox/GzipFilter.pm b/lib/PublicInbox/GzipFilter.pm index 75ba625e..77d570b6 100644 --- a/lib/PublicInbox/GzipFilter.pm +++ b/lib/PublicInbox/GzipFilter.pm @@ -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); } } |