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.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 14AAC1F4B6 for ; Mon, 24 Jun 2019 02:54:16 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 11/57] http: favor DS->write(strref) when reasonable Date: Mon, 24 Jun 2019 02:52:12 +0000 Message-Id: <20190624025258.25592-12-e@80x24.org> In-Reply-To: <20190624025258.25592-1-e@80x24.org> References: <20190624025258.25592-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This can avoid large memory copies when strings can't be copy-on-write and saves us the trouble of creating new refs in the code. --- lib/PublicInbox/HTTP.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 9a43069f..4f1f88fe 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -209,7 +209,7 @@ sub response_header_write { if (($len || $chunked) && $env->{REQUEST_METHOD} ne 'HEAD') { more($self, $h); } else { - $self->write($h); + $self->write(\$h); } $alive; } @@ -222,7 +222,7 @@ sub chunked_wcb ($) { more($self, sprintf("%x\r\n", bytes::length($_[0]))); more($self, $_[0]); - # use $self->write("\n\n") if you care about real-time + # use $self->write(\"\n\n") if you care about real-time # streaming responses, public-inbox WWW does not. more($self, "\r\n"); } @@ -248,7 +248,7 @@ sub response_done_cb ($$) { sub { my $env = $self->{env}; $self->{env} = undef; - $self->write("0\r\n\r\n") if $alive == 2; + $self->write(\"0\r\n\r\n") if $alive == 2; $self->write(sub{$alive ? next_request($self) : $self->close}); } } @@ -330,7 +330,7 @@ sub more ($$) { return $self->write(substr($_[1], $n, $nlen)); } } - $self->write($_[1]); + $self->write(\($_[1])); } sub input_prepare { @@ -467,7 +467,7 @@ sub read_input_chunked { # unlikely... sub quit { my ($self, $status) = @_; my $h = "HTTP/1.1 $status " . status_message($status) . "\r\n\r\n"; - $self->write($h); + $self->write(\$h); $self->close; } -- EW