diff --git a/esphome/core/automation.h b/esphome/core/automation.h index b41a3555e4..90711cfaee 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -419,16 +419,11 @@ template class Action { template class ActionList { public: void add_action(Action *action) { - if (this->actions_begin_ == nullptr) { - this->actions_begin_ = action; - } else { - // Walk to end of chain - action lists are short and only built during setup(). - // Note: intentionally not using pointer-to-pointer idiom here as it generates larger code. - auto *it = this->actions_begin_; - while (it->next_ != nullptr) - it = it->next_; - it->next_ = action; - } + // Walk to end of chain - action lists are short and only built during setup() + Action **tail = &this->actions_begin_; + while (*tail != nullptr) + tail = &(*tail)->next_; + *tail = action; } void add_actions(const std::initializer_list *> &actions) { // Find tail once, then append all actions in a single pass