From de171db50eccfe480777a12098f9876d2a1d0723 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Mar 2026 00:57:16 -1000 Subject: [PATCH] [core] Replace std::bind with lambda in DelayAction Replace std::bind(&DelayAction::play_next_, this, x...) with a [this, x...] lambda in the argument-forwarding path. --- esphome/core/base_automation.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/core/base_automation.h b/esphome/core/base_automation.h index 67e1755cc9..985f26e711 100644 --- a/esphome/core/base_automation.h +++ b/esphome/core/base_automation.h @@ -188,7 +188,7 @@ template class DelayAction : public Action, public Compon // Issue #10264: This is a workaround for parallel script delays interfering with each other. // Optimization: For no-argument delays (most common case), use direct lambda - // instead of std::bind to avoid bind overhead (~16 bytes heap + faster execution) + // to avoid overhead from capturing arguments by value if constexpr (sizeof...(Ts) == 0) { App.scheduler.set_timer_common_( this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL, nullptr, @@ -196,9 +196,9 @@ template class DelayAction : public Action, public Compon [this]() { this->play_next_(); }, /* is_retry= */ false, /* skip_cancel= */ this->num_running_ > 1); } else { - // For delays with arguments, use std::bind to preserve argument values + // For delays with arguments, capture by value to preserve argument values // Arguments must be copied because original references may be invalid after delay - auto f = std::bind(&DelayAction::play_next_, this, x...); + auto f = [this, x...]() { this->play_next_(x...); }; App.scheduler.set_timer_common_(this, Scheduler::SchedulerItem::TIMEOUT, Scheduler::NameType::NUMERIC_ID_INTERNAL, nullptr, static_cast(InternalSchedulerID::DELAY_ACTION), this->delay_.value(x...), std::move(f),