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 e560adef21.
Pick-to: 6.7
Change-Id: I269b54e51ba09ac595ac4e4f255209778819adad
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
bb10
parent
5b6c6dab63
commit
a564618838
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue