[text] Avoid string copies in callbacks by passing const ref (#12504)
This commit is contained in:
@@ -23,7 +23,7 @@ void Text::publish_state(const std::string &state) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Text::add_on_state_callback(std::function<void(std::string)> &&callback) {
|
||||
void Text::add_on_state_callback(std::function<void(const std::string &)> &&callback) {
|
||||
this->state_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Text : public EntityBase {
|
||||
/// Instantiate a TextCall object to modify this text component's state.
|
||||
TextCall make_call() { return TextCall(this); }
|
||||
|
||||
void add_on_state_callback(std::function<void(std::string)> &&callback);
|
||||
void add_on_state_callback(std::function<void(const std::string &)> &&callback);
|
||||
|
||||
protected:
|
||||
friend class TextCall;
|
||||
@@ -44,7 +44,7 @@ class Text : public EntityBase {
|
||||
*/
|
||||
virtual void control(const std::string &value) = 0;
|
||||
|
||||
CallbackManager<void(std::string)> state_callback_;
|
||||
CallbackManager<void(const std::string &)> state_callback_;
|
||||
};
|
||||
|
||||
} // namespace text
|
||||
|
||||
Reference in New Issue
Block a user