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 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 238 LOG_TRACE(this, "Message received on topic '" + topic + "': " + payload);
239 239  
... ...
src/ClientImpl.h
... ... @@ -46,7 +46,7 @@ public:
46 46 void sendUnsubscribe(const std::string &topic); ///< Send an unsubscribe message to the broker.
47 47 void connectionStateChange(bool connected); ///< Called when a connection goes from CONNECTING state to CONNECTED state or visa versa.
48 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 51 State state = State::DISCONNECTED; ///< The current state of the client.
52 52 std::mutex state_mutex; ///< Mutex to protect state changes.
... ...
src/Connection.cpp
... ... @@ -19,7 +19,7 @@
19 19 Connection::Connection(TrueMQTT::Client::LogLevel log_level,
20 20 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger,
21 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 23 const std::function<void(bool)> connection_change_callback,
24 24 const std::string &host,
25 25 int port)
... ... @@ -370,7 +370,7 @@ void TrueMQTT::Client::Impl::connect()
370 370 {
371 371 this->connection = std::make_unique<Connection>(
372 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 374 { this->messageReceived(std::move(topic), std::move(payload)); },
375 375 [this](bool connected)
376 376 { this->connectionStateChange(connected); },
... ...
src/Connection.h
... ... @@ -26,7 +26,7 @@ public:
26 26 Connection(TrueMQTT::Client::LogLevel log_level,
27 27 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger,
28 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 30 const std::function<void(bool)> connection_change_callback,
31 31 const std::string &host,
32 32 int port);
... ... @@ -61,7 +61,7 @@ private:
61 61 const std::function<void(TrueMQTT::Client::LogLevel, std::string)> logger;
62 62  
63 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 65 const std::function<void(bool)> m_connection_change_callback;
66 66  
67 67 const std::string &m_host; ///< The hostname or IP address to connect to.
... ...