From 78d1ce422251ff575c91ba8a797862e319ade2a0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 28 Mar 2026 10:54:48 -1000 Subject: [PATCH] Use pointer-to-pointer idiom in add_action() for consistency and smaller code --- esphome/core/automation.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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