From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 12BB91F626 for ; Sat, 10 Sep 2022 08:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797934; bh=DQv1iQMCLzsbyHdJMJHRpLLbH9bp81Ay6/YEYSrrM3I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nG10bp8cmb40wJmBEsa30/sJrxutnCo1/3BKntvWPSqW+GVA3E/h1GESblQotKXNP PaEfnXlz4h8hY7/hdyXMUDel7iAGynDpl/nt6sBD25r4h/hqQMqjoVzcWbWwFp67ZQ gnivzJn6wZeJJct8prpYK0+WoV7GnxoCrVtF4LCM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 13/38] gzip_filter: ->translate can reuse zmore/zflush Date: Sat, 10 Sep 2022 08:17:04 +0000 Message-Id: <20220910081729.2011934-14-e@80x24.org> In-Reply-To: <20220910081729.2011934-1-e@80x24.org> References: <20220910081729.2011934-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can work towards delaying zlib context allocations in future commits, too. --- lib/PublicInbox/GzipFilter.pm | 15 ++++----------- 1 file 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); } }