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 <ivan.solovev@qt.io> (cherry picked from commit a56461883830cecf281b1d6db5e7d6103154d3d9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
963e886c6f
commit
8d4d0cfaf4
@ -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
|
||||
|
@ -9,6 +9,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 {
|
||||
@ -72,7 +74,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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user