diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-04-18 09:09:48 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-04-18 19:06:02 +0200 |
commit | a56461883830cecf281b1d6db5e7d6103154d3d9 (patch) | |
tree | e87352d503bb04b27a642db0c28073516d3820c2 /tests/auto | |
parent | 5b6c6dab632a32a09963453b08731e9e33334e9a (diff) |
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.
Pick-to: 6.7
Change-Id: I269b54e51ba09ac595ac4e4f255209778819adad
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/network/access/qrestaccessmanager/httptestserver.cpp | 4 | ||||
-rw-r--r-- | tests/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 00995920d5..25869eb46b 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 ead6590a55..0a94b2c8a6 100644 --- a/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h +++ b/tests/auto/network/access/qrestaccessmanager/httptestserver_p.h @@ -10,6 +10,8 @@ #include <QtCore/qmap.h> #include <QtCore/qurl.h> +#include <functional> + // This struct is used for parsing the incoming network request data into, as well // as getting the response data from the testcase struct HttpData { @@ -73,7 +75,7 @@ public: // Settable callback for testcase. Gives the received request data, and takes in response data using Handler = std::function<void(const HttpData &request, HttpData &response, ResponseControl &control)>; - void setHandler(const Handler &handler); + void setHandler(Handler handler) { m_handler = std::move(handler); } private slots: void handleConnected(); |