From 1459c16fb8fe86a8522b11e7f9921173b75e8c0f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 1 May 2021 10:59:15 -0700 Subject: [PATCH] http: Skip processing response body for void. No need to decompress or copy between buffers. --- Common/Buffer.h | 9 +++++++++ Common/Net/HTTPClient.cpp | 32 +++++++++++++++++--------------- Core/Reporting.cpp | 4 ++-- Core/WebServer.cpp | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Common/Buffer.h b/Common/Buffer.h index 7a271bf8ba..2e92669b29 100644 --- a/Common/Buffer.h +++ b/Common/Buffer.h @@ -10,8 +10,15 @@ class Buffer { public: Buffer(); + Buffer(Buffer &&) = default; ~Buffer(); + static Buffer Void() { + Buffer buf; + buf.void_ = true; + return buf; + } + // Write max [length] bytes to the returned pointer. // Any other operation on this Buffer invalidates the pointer. char *Append(size_t length); @@ -65,10 +72,12 @@ public: size_t size() const { return data_.size(); } bool empty() const { return size() == 0; } void clear() { data_.resize(0); } + bool IsVoid() { return void_; } protected: // TODO: Find a better internal representation, like a cord. std::vector data_; + bool void_ = false; private: DISALLOW_COPY_AND_ASSIGN(Buffer); diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index b49478e34f..f06072cc7d 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -432,23 +432,25 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vectorprogress); - } else { - output->Append(*readbuf); - } + if (!output->IsVoid()) { + if (chunked) { + DeChunk(readbuf, output, contentLength, &progress->progress); + } else { + output->Append(*readbuf); + } - // If it's gzipped, we decompress it and put it back in the buffer. - if (gzip) { - std::string compressed, decompressed; - output->TakeAll(&compressed); - bool result = decompress_string(compressed, &decompressed); - if (!result) { - ERROR_LOG(IO, "Error decompressing using zlib"); - progress->progress = 0.0f; - return -1; + // If it's gzipped, we decompress it and put it back in the buffer. + if (gzip) { + std::string compressed, decompressed; + output->TakeAll(&compressed); + bool result = decompress_string(compressed, &decompressed); + if (!result) { + ERROR_LOG(IO, "Error decompressing using zlib"); + progress->progress = 0.0f; + return -1; + } + output->Append(decompressed); } - output->Append(decompressed); } progress->progress = 1.0f; diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index e00e56730f..487dd9c295 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -262,11 +262,11 @@ namespace Reporting { http::Client http; http::RequestProgress progress; - Buffer theVoid; + Buffer theVoid = Buffer::Void(); http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION)); - if (output == NULL) + if (output == nullptr) output = &theVoid; const char *serverHost = ServerHostname(); diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index 35ea2ff48e..9b7f388543 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -64,7 +64,7 @@ static bool RegisterServer(int port) { bool success = false; http::Client http; http::RequestProgress progress; - Buffer theVoid; + Buffer theVoid = Buffer::Void(); http.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));