From 88793cbc1a4c00bdf84155f6696a8288fda82bed Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Aug 2022 21:00:21 +0200 Subject: [PATCH] output/httpd: avoid extra buffer copy if possible --- src/output/plugins/httpd/HttpdOutputPlugin.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index fa88bdda3..de4245e6b 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -169,6 +169,15 @@ HttpdOutput::ReadPage() noexcept unflushed_input = 0; if (r.data() != b.data()) { + if (size == 0 && r.size() >= sizeof(buffer) / 2) + /* if the returned memory area is + large (and nothing has been written + to the stack buffer yet), copy + right from the returned memory + area, avoiding the copy into the + buffer*/ + return std::make_shared(r); + /* if the encoder did not write to the given buffer but instead returned its own buffer, we need to copy it so we have a contiguous