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 91EA41F629 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=MLEBraI5gO7FOuO81f73rXxHWcHOAFrU3/uDkDckQiw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A9J0OCypvRMjXyEHobnyjfGM9ijd0FBnt0vArQV/EpKkg9v8LCrKMHN8J2oqHTCOC kiVOyyis6J1AEo6aiToi4DQN5xdzy0JiS8CEWNxre4OpTzFmMFLz6pafBpLkFGDIk8 9dchykn62tZ4mXcwzu0byROpHGsddXFCQIqKv6DI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 16/38] view: attach_link: reduce obuf manipulation Date: Sat, 10 Sep 2022 08:17:07 +0000 Message-Id: <20220910081729.2011934-17-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: This is another steep towards reducing the maximum size of an obuf by eventually doing compression earlier while we render messages as HTML. And do some golfing while we're at it... --- lib/PublicInbox/View.pm | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1b55fe77..0fe645ca 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -524,7 +524,6 @@ sub attach_link ($$$$;$) { # downloads for 0-byte multipart attachments return unless $part->{bdy}; - my $nl = $idx eq '1' ? '' : "\n"; # like join("\n", ...) my $size = length($part->body); delete $part->{bdy}; # save memory @@ -540,23 +539,17 @@ sub attach_link ($$$$;$) { } else { $sfn = 'a.bin'; } - my $rv = $ctx->{obuf}; - $$rv .= qq($nl{mhref}$idx-$sfn">); - if ($err) { - $$rv .= <{mhref}$idx-$sfn">); + $rv .= <header('Content-Description') // $fn // ''; - $desc = ascii_html($desc); - $$rv .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]"; - $$rv .= "\n"; - - $$rv .= submsg_hdr($ctx, $part) if $part->{is_submsg}; - - undef; + $rv .= ascii_html($desc)." --]\n[-- " if $desc ne ''; + $rv .= "Type: $ct, Size: $size bytes --]\n"; + $rv .= submsg_hdr($ctx, $part) if $part->{is_submsg}; + $rv; } sub add_text_body { # callback for each_part @@ -568,10 +561,9 @@ sub add_text_body { # callback for each_part my ($part, $depth, $idx) = @$p; my $ct = $part->content_type || 'text/plain'; my $fn = $part->filename; - my ($s, $err) = msg_part_text($part, $ct); - return attach_link($ctx, $ct, $p, $fn) unless defined $s; - my $rv = $ctx->{obuf}; + my ($s, $err) = msg_part_text($part, $ct); + $s // return $$rv .= (attach_link($ctx, $ct, $p, $fn) // ''); if ($part->{is_submsg}) { $$rv .= submsg_hdr($ctx, $part); $$rv .= "\n"; @@ -623,7 +615,7 @@ sub add_text_body { # callback for each_part undef $s; # free memory if (defined($fn) || ($depth > 0 && !$part->{is_submsg}) || $err) { # badly-encoded message with $err? tell the world about it! - attach_link($ctx, $ct, $p, $fn, $err); + $$rv .= attach_link($ctx, $ct, $p, $fn, $err); $$rv .= "\n"; } delete $part->{bdy}; # save memory