mirror of
https://github.com/esphome/esphome.git
synced 2025-08-05 18:07:47 +00:00
tweak
This commit is contained in:
parent
c45901746b
commit
ad51e647af
@ -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,
|
void HOT Scheduler::set_timer_common_(Component *component, SchedulerItem::Type type, bool is_static_string,
|
||||||
const void *name_ptr, uint32_t delay, std::function<void()> func) {
|
const void *name_ptr, uint32_t delay, std::function<void()> func) {
|
||||||
// Get the name as const char*
|
// Get the name as const char*
|
||||||
const char *name_cstr =
|
const char *name_cstr = this->get_name_cstr_(is_static_string, name_ptr);
|
||||||
is_static_string ? static_cast<const char *>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
|
|
||||||
|
|
||||||
if (delay == SCHEDULER_DONT_RUN) {
|
if (delay == SCHEDULER_DONT_RUN) {
|
||||||
// Still need to cancel existing timer if name is not empty
|
// 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,
|
bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, const void *name_ptr,
|
||||||
SchedulerItem::Type type) {
|
SchedulerItem::Type type) {
|
||||||
// Get the name as const char*
|
// Get the name as const char*
|
||||||
const char *name_cstr =
|
const char *name_cstr = this->get_name_cstr_(is_static_string, name_ptr);
|
||||||
is_static_string ? static_cast<const char *>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
|
|
||||||
|
|
||||||
// Handle null or empty names
|
// Handle null or empty names
|
||||||
if (name_cstr == nullptr)
|
if (name_cstr == nullptr)
|
||||||
|
@ -145,6 +145,11 @@ class Scheduler {
|
|||||||
// Helper to cancel items by name - must be called with lock held
|
// 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);
|
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<const char *>(name_ptr) : static_cast<const std::string *>(name_ptr)->c_str();
|
||||||
|
}
|
||||||
|
|
||||||
// Common implementation for cancel operations
|
// Common implementation for cancel operations
|
||||||
bool cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
bool cancel_item_(Component *component, bool is_static_string, const void *name_ptr, SchedulerItem::Type type);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user