From 676f13ac53bf96eab869514fe9fafcc0169874ab Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jun 2019 02:52:12 +0000 Subject: http: favor DS->write(strref) when reasonable 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(-) (limited to 'lib/PublicInbox') 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; } -- cgit v1.2.3-24-ge0c7