]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: use array for highlighted blob display
authorEric Wong <e@80x24.org>
Mon, 29 Aug 2022 09:26:34 +0000 (09:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 29 Aug 2022 19:05:45 +0000 (19:05 +0000)
This can avoid at least one expensive copy for displaying
large blobs with syntax highlighting.

However, we cannot blindly change everything to arrays, either:
the cost of invoking Compress::Raw::Zlib->deflate must be taken
into account.  Joining short strings via `.=', `.', `join' or
interpolation is typically faster since it avoids ->deflate
method calls (and non-magic perlops are the fastest dispatches
in Perl).

lib/PublicInbox/ViewVCS.pm

index 23524ac00b7e1a937b8924ba868adaa83f0c58d1..8fb0844d989f0fb8d67cfa534f20fc536b5f3c9a 100644 (file)
@@ -313,15 +313,15 @@ EOM
                $$blob = ascii_html($$blob);
        }
 
-       # using some of the same CSS class names and ids as cgit
-       html_page($ctx, 200, "<pre>$oid $type $size bytes $raw_link</pre>" .
+       my $x = "<pre>$oid $type $size bytes $raw_link</pre>" .
                "<hr /><table\nclass=blob>".
-               "<tr><td\nclass=linenumbers><pre>" . join('', map {
-                       sprintf("<a id=n$_ href=#n$_>% ${pad}u</a>\n", $_)
-               } (1..$nl)) . '</pre></td>' .
-               '<td><pre> </pre></td>'. # pad for non-CSS users
-               "<td\nclass=lines><pre\nstyle='white-space:pre'><code>" .
-               $ctx->{-linkify}->linkify_2($$blob) .
+               "<tr><td\nclass=linenumbers><pre>";
+       $x .= sprintf("<a id=n$_ href=#n$_>% ${pad}u</a>\n", $_) for (1..$nl);
+       $x .= '</pre></td><td><pre> </pre></td>'. # pad for non-CSS users
+               "<td\nclass=lines><pre\nstyle='white-space:pre'><code>";
+
+       # using some of the same CSS class names and ids as cgit
+       html_page($ctx, 200, $x, $ctx->{-linkify}->linkify_2($$blob),
                '</code></pre></td></tr></table>'.dbg_log($ctx));
 }