[select] Eliminate string allocation in state callbacks (#12505)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
1 parent
dc8f7abce2
commit
91c504061b
5 files changed
+12
-10
No files matched your search
@@ -32,8 +32,7 @@ void Select::publish_state(size_t index) {
|
||||
this->state = option; // Update deprecated member for backward compatibility
|
||||
#pragma GCC diagnostic pop
|
||||
ESP_LOGD(TAG, "'%s': Sending state %s (index %zu)", this->get_name().c_str(), option, index);
|
||||
// Callback signature requires std::string, create temporary for compatibility
|
||||
this->state_callback_.call(std::string(option), index);
|
||||
this->state_callback_.call(index);
|
||||
#if defined(USE_SELECT) && defined(USE_CONTROLLER_REGISTRY)
|
||||
ControllerRegistry::notify_select_update(this);
|
||||
#endif
|
||||
@@ -41,7 +40,7 @@ void Select::publish_state(size_t index) {
|
||||
|
||||
const char *Select::current_option() const { return this->has_state() ? this->option_at(this->active_index_) : ""; }
|
||||
|
||||
void Select::add_on_state_callback(std::function<void(std::string, size_t)> &&callback) {
|
||||
void Select::add_on_state_callback(std::function<void(size_t)> &&callback) {
|
||||
this->state_callback_.add(std::move(callback));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user