From 5b0fbbaada91766de1c4ee950378a82bc8116149 Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Thu, 30 Sep 2021 16:25:08 +0200 Subject: [PATCH] Replace std::move() with const references where possible (#2421) * Replace std::move() with const references where possible * Fix formatting --- esphome/components/http_request/http_request.h | 2 +- esphome/components/pipsolar/output/pipsolar_output.h | 2 +- esphome/components/pipsolar/switch/pipsolar_switch.h | 4 ++-- esphome/components/rf_bridge/rf_bridge.h | 3 +-- esphome/components/select/automation.h | 2 +- esphome/components/sim800l/sim800l.h | 2 +- esphome/components/template/select/template_select.h | 2 +- esphome/components/text_sensor/automation.h | 4 ++-- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/esphome/components/http_request/http_request.h b/esphome/components/http_request/http_request.h index 511096e7fa..9cc027b58d 100644 --- a/esphome/components/http_request/http_request.h +++ b/esphome/components/http_request/http_request.h @@ -40,7 +40,7 @@ class HttpRequestComponent : public Component { void set_method(const char *method) { this->method_ = method; } void set_useragent(const char *useragent) { this->useragent_ = useragent; } void set_timeout(uint16_t timeout) { this->timeout_ = timeout; } - void set_body(std::string body) { this->body_ = std::move(body); } + void set_body(const std::string &body) { this->body_ = body; } void set_headers(std::list
headers) { this->headers_ = std::move(headers); } void send(const std::vector &response_triggers); void close(); diff --git a/esphome/components/pipsolar/output/pipsolar_output.h b/esphome/components/pipsolar/output/pipsolar_output.h index 932efe01c2..fe783cf034 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.h +++ b/esphome/components/pipsolar/output/pipsolar_output.h @@ -13,7 +13,7 @@ class PipsolarOutput : public output::FloatOutput { public: PipsolarOutput() {} void set_parent(Pipsolar *parent) { this->parent_ = parent; } - void set_set_command(std::string command) { this->set_command_ = std::move(command); }; + void set_set_command(const std::string &command) { this->set_command_ = command; }; void set_possible_values(std::vector possible_values) { this->possible_values_ = std::move(possible_values); } void set_value(float value) { this->write_state(value); }; diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.h b/esphome/components/pipsolar/switch/pipsolar_switch.h index 3fe4c7dfa1..11ff6c853a 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.h +++ b/esphome/components/pipsolar/switch/pipsolar_switch.h @@ -10,8 +10,8 @@ class Pipsolar; class PipsolarSwitch : public switch_::Switch, public Component { public: void set_parent(Pipsolar *parent) { this->parent_ = parent; }; - void set_on_command(std::string command) { this->on_command_ = std::move(command); }; - void set_off_command(std::string command) { this->off_command_ = std::move(command); }; + void set_on_command(const std::string &command) { this->on_command_ = command; }; + void set_off_command(const std::string &command) { this->off_command_ = command; }; void dump_config() override; protected: diff --git a/esphome/components/rf_bridge/rf_bridge.h b/esphome/components/rf_bridge/rf_bridge.h index 2fa4eb05c5..9156d995bc 100644 --- a/esphome/components/rf_bridge/rf_bridge.h +++ b/esphome/components/rf_bridge/rf_bridge.h @@ -85,8 +85,7 @@ class RFBridgeReceivedCodeTrigger : public Trigger { class RFBridgeReceivedAdvancedCodeTrigger : public Trigger { public: explicit RFBridgeReceivedAdvancedCodeTrigger(RFBridgeComponent *parent) { - parent->add_on_advanced_code_received_callback( - [this](RFBridgeAdvancedData data) { this->trigger(std::move(data)); }); + parent->add_on_advanced_code_received_callback([this](const RFBridgeAdvancedData &data) { this->trigger(data); }); } }; diff --git a/esphome/components/select/automation.h b/esphome/components/select/automation.h index 59525f879e..1e0bfed63d 100644 --- a/esphome/components/select/automation.h +++ b/esphome/components/select/automation.h @@ -10,7 +10,7 @@ namespace select { class SelectStateTrigger : public Trigger { public: explicit SelectStateTrigger(Select *parent) { - parent->add_on_state_callback([this](std::string value) { this->trigger(std::move(value)); }); + parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); }); } }; diff --git a/esphome/components/sim800l/sim800l.h b/esphome/components/sim800l/sim800l.h index fa9c392bfc..21e9ac4a50 100644 --- a/esphome/components/sim800l/sim800l.h +++ b/esphome/components/sim800l/sim800l.h @@ -74,7 +74,7 @@ class Sim800LReceivedMessageTrigger : public Trigger { public: explicit Sim800LReceivedMessageTrigger(Sim800LComponent *parent) { parent->add_on_sms_received_callback( - [this](std::string message, std::string sender) { this->trigger(std::move(message), std::move(sender)); }); + [this](const std::string &message, const std::string &sender) { this->trigger(message, sender); }); } }; diff --git a/esphome/components/template/select/template_select.h b/esphome/components/template/select/template_select.h index e24eb6e880..2f00765c3d 100644 --- a/esphome/components/template/select/template_select.h +++ b/esphome/components/template/select/template_select.h @@ -19,7 +19,7 @@ class TemplateSelect : public select::Select, public PollingComponent { Trigger *get_set_trigger() const { return this->set_trigger_; } void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; } - void set_initial_option(std::string initial_option) { this->initial_option_ = std::move(initial_option); } + void set_initial_option(const std::string &initial_option) { this->initial_option_ = initial_option; } void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; } protected: diff --git a/esphome/components/text_sensor/automation.h b/esphome/components/text_sensor/automation.h index dd02aeaf3b..d7286845e0 100644 --- a/esphome/components/text_sensor/automation.h +++ b/esphome/components/text_sensor/automation.h @@ -12,14 +12,14 @@ namespace text_sensor { class TextSensorStateTrigger : public Trigger { public: explicit TextSensorStateTrigger(TextSensor *parent) { - parent->add_on_state_callback([this](std::string value) { this->trigger(std::move(value)); }); + parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); }); } }; class TextSensorStateRawTrigger : public Trigger { public: explicit TextSensorStateRawTrigger(TextSensor *parent) { - parent->add_on_raw_state_callback([this](std::string value) { this->trigger(std::move(value)); }); + parent->add_on_raw_state_callback([this](const std::string &value) { this->trigger(value); }); } };