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 7E6A31F69C for ; Sat, 10 Sep 2022 08:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797937; bh=q9MmgRVObm2O031vjnNAklMsVu11/LZ9gjohby8ClIs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=n0y9JyUko+e7OsIwV+PZV6CkmdOrt/q6GUnF5adv1b3zv+amtFwTwgYj0JOb+cpbT 4otndVc2SKlnLDekl6QKgNKzMmZaOgyU38r6mdoi6aqYa0dgoI7UGtf1SyL+IsTaug wpdG5eKOSaS11Tgtla+QxDFRGx1opc4rtYwHweKs= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 31/38] www_static: switch to `print $zfh', and optimize Date: Sat, 10 Sep 2022 08:17:22 +0000 Message-Id: <20220910081729.2011934-32-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: ->zmore isn't cheap, and we can be smarter about how we place newlines to avoid a `join' operation, now. We can also drop some unused variables, here. --- lib/PublicInbox/WwwStatic.pm | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm index eeb5e565..1c1a3d38 100644 --- a/lib/PublicInbox/WwwStatic.pm +++ b/lib/PublicInbox/WwwStatic.pm @@ -275,12 +275,11 @@ sub dir_response ($$$) { my $path_info = $env->{PATH_INFO}; push @entries, '..' if $path_info ne '/'; for my $base (@entries) { + my @st = stat($fs_path . $base) or next; # unlikely my $href = ascii_html(uri_escape_utf8($base)); my $name = ascii_html($base); - my @st = stat($fs_path . $base) or next; # unlikely - my ($gzipped, $uncompressed, $hsize); - my $entry = ''; my $mtime = $st[9]; + my ($entry, $hsize); if (-d _) { $href .= '/'; $name .= '/'; @@ -296,12 +295,12 @@ sub dir_response ($$$) { next; } # 54 = 80 - (SP length(strftime(%Y-%m-%d %k:%M)) SP human_size) - $hsize = sprintf('% 8s', $hsize); my $pad = 54 - length($name); $pad = 1 if $pad <= 0; - $entry .= qq($name) . (' ' x $pad); - $mtime = strftime('%Y-%m-%d %k:%M', gmtime($mtime)); - $entry .= $mtime . $hsize; + $entry = qq(\n$name) . + (' ' x $pad) . + strftime('%Y-%m-%d %k:%M', gmtime($mtime)) . + sprintf('% 8s', $hsize); } # filter out '.gz' files as long as the mtime matches the @@ -309,17 +308,16 @@ sub dir_response ($$$) { delete(@other{keys %want_gz}); @entries = ((map { ${$dirs{$_}} } sort keys %dirs), (map { ${$other{$_}} } sort keys %other)); - my $path_info_html = ascii_html($path_info); - my $h = [qw(Content-Type text/html Content-Length), undef]; - my $gzf = gzf_maybe($h, $env); - $gzf->zmore("Index of $path_info_html" . - ${$self->{style}} . - "
Index of $path_info_html

\n");
-	$gzf->zmore(join("\n", @entries));
-	my $out = $gzf->zflush("

\n"); - $h->[3] = length($out); - [ 200, $h, [ $out ] ] + my @h = qw(Content-Type text/html); + my $gzf = gzf_maybe(\@h, $env); + print { $gzf->zfh } 'Index of ', $path_info_html, + '', ${$self->{style}}, '
Index of ',
+		$path_info_html, '

', @entries,
+		'

'; + my $out = $gzf->zflush; + push @h, 'Content-Length', length($out); + [ 200, \@h, [ $out ] ] } sub call { # PSGI app endpoint