From 8d4d0cfaf42832228da08939c51f760bc82028c6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 18 Apr 2024 09:09:48 +0200 Subject: [PATCH] HttpTestServer: pass std::function by value and move into place Virtually all callers of this function (will) pass rvalues, so take the std::function by value (reaping C++17 guaranteed copy elision) and std::move() into the member variable ("perfect sink"). Like for many owning types, moves are much cheaper than copies for std::function, because the external state is merely tranferred between objects, and not copied. Amends e560adef213301318dcc13d4db155624846e0420. Change-Id: I269b54e51ba09ac595ac4e4f255209778819adad Reviewed-by: Ivan Solovev (cherry picked from commit a56461883830cecf281b1d6db5e7d6103154d3d9) Reviewed-by: Qt Cherry-pick Bot --- .../auto/network/access/qrestaccessmanager/httptestserver.cpp | 4 ---- .../auto/network/access/qrestaccessmanager/httptestserver_p.h | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/auto/network/access/qrestaccessmanager/httptestserver.cpp b/tests/auto/network/access/qrestaccessmanager/httptestserver.cpp index 089342ff8bf..c8a26b317a3 100644 --- a/tests/auto/network/access/qrestaccessmanager/httptestserver.cpp +++ b/tests/auto/network/access/qrestaccessmanager/httptestserver.cpp @@ -31,10 +31,6 @@ QUrl HttpTestServer::url() return QUrl(u"http://127.0.0.1:%1"_s.arg(serverPort())); } -void HttpTestServer::setHandler(const Handler &handler) { - m_handler = handler; -} - void HttpTestServer::handleConnected() { Q_ASSERT(!m_socket); // No socket must exist previously, this is a single-connection server diff --git a/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h b/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h index 1498c4bdb7e..60cd603c92d 100644 --- a/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h +++ b/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h @@ -9,6 +9,8 @@ #include #include +#include + // This struct is used for parsing the incoming network request data into, as well // as getting the response data from the testcase struct HttpData { @@ -72,7 +74,7 @@ public: // Settable callback for testcase. Gives the received request data, and takes in response data using Handler = std::function; - void setHandler(const Handler &handler); + void setHandler(Handler handler) { m_handler = std::move(handler); } private slots: void handleConnected();