From 0c313dbe6665c66862bbac870127e492afab2e92 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 28 Mar 2026 10:34:18 -1000 Subject: [PATCH] Optimize add_actions() to find tail once instead of re-walking per action --- esphome/core/automation.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 3cb8caa026..72bcc3d707 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -430,8 +430,13 @@ template class ActionList { } } void add_actions(const std::initializer_list *> &actions) { + // Find tail once, then append all actions in a single pass + Action **tail = &this->actions_begin_; + while (*tail != nullptr) + tail = &(*tail)->next_; for (auto *action : actions) { - this->add_action(action); + *tail = action; + tail = &action->next_; } } // Force-inline: part of the Trigger→Automation→ActionList forwarding