Commit b61afde09fa34629e8fa6bb978fad620255ef4b8

Authored by Patric Stout
1 parent 62bf528f

chore(packet): no need for &&, std::move will do the right thing on std::string too

Just for small strings it will copy, and only large strings will
actually be moved.
src/Client.cpp
@@ -233,7 +233,7 @@ void Client::Impl::toPublishQueue(const std::string &topic, const std::string &p @@ -233,7 +233,7 @@ void Client::Impl::toPublishQueue(const std::string &topic, const std::string &p
233 this->publish_queue.push_back({topic, payload, retain}); 233 this->publish_queue.push_back({topic, payload, retain});
234 } 234 }
235 235
236 -void Client::Impl::messageReceived(std::string &&topic, std::string &&payload) 236 +void Client::Impl::messageReceived(std::string topic, std::string payload)
237 { 237 {
238 LOG_TRACE(this, "Message received on topic '" + topic + "': " + payload); 238 LOG_TRACE(this, "Message received on topic '" + topic + "': " + payload);
239 239
src/ClientImpl.h
@@ -46,7 +46,7 @@ public: @@ -46,7 +46,7 @@ public:
46 void sendUnsubscribe(const std::string &topic); ///< Send an unsubscribe message to the broker. 46 void sendUnsubscribe(const std::string &topic); ///< Send an unsubscribe message to the broker.
47 void connectionStateChange(bool connected); ///< Called when a connection goes from CONNECTING state to CONNECTED state or visa versa. 47 void connectionStateChange(bool connected); ///< Called when a connection goes from CONNECTING state to CONNECTED state or visa versa.
48 void toPublishQueue(const std::string &topic, const std::string &payload, bool retain); ///< Add a publish message to the publish queue. 48 void toPublishQueue(const std::string &topic, const std::string &payload, bool retain); ///< Add a publish message to the publish queue.
49 - void messageReceived(std::string &&topic, std::string &&payload); ///< Called when a message is received from the broker. 49 + void messageReceived(std::string topic, std::string payload); ///< Called when a message is received from the broker.
50 50
51 State state = State::DISCONNECTED; ///< The current state of the client. 51 State state = State::DISCONNECTED; ///< The current state of the client.
52 std::mutex state_mutex; ///< Mutex to protect state changes. 52 std::mutex state_mutex; ///< Mutex to protect state changes.
src/Connection.cpp
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 Connection::Connection(TrueMQTT::Client::LogLevel log_level, 19 Connection::Connection(TrueMQTT::Client::LogLevel log_level,
20 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger, 20 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger,
21 const std::function<void(TrueMQTT::Client::Error, std::string)> error_callback, 21 const std::function<void(TrueMQTT::Client::Error, std::string)> error_callback,
22 - const std::function<void(std::string &&, std::string &&)> publish_callback, 22 + const std::function<void(std::string, std::string)> publish_callback,
23 const std::function<void(bool)> connection_change_callback, 23 const std::function<void(bool)> connection_change_callback,
24 const std::string &host, 24 const std::string &host,
25 int port) 25 int port)
@@ -370,7 +370,7 @@ void TrueMQTT::Client::Impl::connect() @@ -370,7 +370,7 @@ void TrueMQTT::Client::Impl::connect()
370 { 370 {
371 this->connection = std::make_unique<Connection>( 371 this->connection = std::make_unique<Connection>(
372 this->log_level, this->logger, this->error_callback, 372 this->log_level, this->logger, this->error_callback,
373 - [this](std::string &&topic, std::string &&payload) 373 + [this](std::string topic, std::string payload)
374 { this->messageReceived(std::move(topic), std::move(payload)); }, 374 { this->messageReceived(std::move(topic), std::move(payload)); },
375 [this](bool connected) 375 [this](bool connected)
376 { this->connectionStateChange(connected); }, 376 { this->connectionStateChange(connected); },
src/Connection.h
@@ -26,7 +26,7 @@ public: @@ -26,7 +26,7 @@ public:
26 Connection(TrueMQTT::Client::LogLevel log_level, 26 Connection(TrueMQTT::Client::LogLevel log_level,
27 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger, 27 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger,
28 const std::function<void(TrueMQTT::Client::Error, std::string)> error_callback, 28 const std::function<void(TrueMQTT::Client::Error, std::string)> error_callback,
29 - const std::function<void(std::string &&, std::string &&)> publish_callback, 29 + const std::function<void(std::string, std::string)> publish_callback,
30 const std::function<void(bool)> connection_change_callback, 30 const std::function<void(bool)> connection_change_callback,
31 const std::string &host, 31 const std::string &host,
32 int port); 32 int port);
@@ -61,7 +61,7 @@ private: @@ -61,7 +61,7 @@ private:
61 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger; 61 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger;
62 62
63 const std::function<void(TrueMQTT::Client::Error, std::string)> m_error_callback; 63 const std::function<void(TrueMQTT::Client::Error, std::string)> m_error_callback;
64 - const std::function<void(std::string &&, std::string &&)> m_publish_callback; 64 + const std::function<void(std::string, std::string)> m_publish_callback;
65 const std::function<void(bool)> m_connection_change_callback; 65 const std::function<void(bool)> m_connection_change_callback;
66 66
67 const std::string &m_host; ///< The hostname or IP address to connect to. 67 const std::string &m_host; ///< The hostname or IP address to connect to.