From ad51e647af26574117af7c9bc7afdc712a1786ab Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 18:48:50 -0500 Subject: [PATCH] tweak --- esphome/core/scheduler.cpp | 6 ++---- esphome/core/scheduler.h | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index fa0f6c00f6..be8f7db83f 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -62,8 +62,7 @@ static void validate_static_string(const char *name) { void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type type, bool is_static_string, const void *name_ptr, uint32_t delay, std::function func) { // Get the name as const char* - const char *name_cstr = - is_static_string ? static_cast(name_ptr) : static_cast(name_ptr)->c_str(); + const char *name_cstr = this->get_name_cstr_(is_static_string, name_ptr); if (delay == SCHEDULER_DONT_RUN) { // Still need to cancel existing timer if name is not empty @@ -418,8 +417,7 @@ void HOT Scheduler::execute_item_(SchedulerItem *item) { bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type) { // Get the name as const char* - const char *name_cstr = - is_static_string ? static_cast(name_ptr) : static_cast(name_ptr)->c_str(); + const char *name_cstr = this->get_name_cstr_(is_static_string, name_ptr); // Handle null or empty names if (name_cstr == nullptr) diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 9ff6336bd5..f3f78d39af 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -145,6 +145,11 @@ class Scheduler { // Helper to cancel items by name - must be called with lock held bool cancel_item_locked_(Component *component, const char *name, SchedulerItem::Type type, bool defer_only); + // Helper to extract name as const char* from either static string or std::string + inline const char *get_name_cstr_(bool is_static_string, const void *name_ptr) { + return is_static_string ? static_cast(name_ptr) : static_cast(name_ptr)->c_str(); + } + // Common implementation for cancel operations bool cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);