From 939d01dd99d56101b671fe88d0423f86337af207 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 6 Jul 2025 18:08:50 -0500 Subject: [PATCH] preen --- esphome/core/scheduler.cpp | 60 +++++++++++++++++--------------------- esphome/core/scheduler.h | 8 ----- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 773b5775d2..1a38b6a83e 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -430,39 +430,6 @@ bool HOT Scheduler::cancel_item_(Component *component, bool is_static_string, co return this->cancel_item_locked_(component, name_cstr, type); } -// Helper to mark heap items for cancellation and update to_remove_ count -size_t HOT Scheduler::cancel_heap_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type) { - size_t cancelled_count = 0; - - // Cancel items in the main heap - for (auto &item : this->items_) { - if (item->component != component || item->type != type || item->remove) { - continue; - } - const char *item_name = item->get_name(); - if (item_name != nullptr && strcmp(name_cstr, item_name) == 0) { - item->remove = true; - cancelled_count++; - this->to_remove_++; // Track removals for heap items - } - } - - // Cancel items in to_add_ - for (auto &item : this->to_add_) { - if (item->component != component || item->type != type || item->remove) { - continue; - } - const char *item_name = item->get_name(); - if (item_name != nullptr && strcmp(name_cstr, item_name) == 0) { - item->remove = true; - cancelled_count++; - // Don't track removals for to_add_ items - } - } - - return cancelled_count; -} - // Helper to cancel items by name - must be called with lock held bool HOT Scheduler::cancel_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type) { size_t total_cancelled = 0; @@ -481,7 +448,32 @@ bool HOT Scheduler::cancel_item_locked_(Component *component, const char *name_c } } #endif - total_cancelled += this->cancel_heap_item_locked_(component, name_cstr, type); + + // Cancel items in the main heap + for (auto &item : this->items_) { + if (item->component != component || item->type != type || item->remove) { + continue; + } + const char *item_name = item->get_name(); + if (item_name != nullptr && strcmp(name_cstr, item_name) == 0) { + item->remove = true; + total_cancelled++; + this->to_remove_++; // Track removals for heap items + } + } + + // Cancel items in to_add_ + for (auto &item : this->to_add_) { + if (item->component != component || item->type != type || item->remove) { + continue; + } + const char *item_name = item->get_name(); + if (item_name != nullptr && strcmp(name_cstr, item_name) == 0) { + item->remove = true; + total_cancelled++; + // Don't track removals for to_add_ items + } + } return total_cancelled > 0; } diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index 06a0543881..13e36601e3 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -140,14 +140,6 @@ 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); -#if !defined(USE_ESP8266) && !defined(USE_RP2040) - // Helper to mark deferred items for cancellation (no to_remove_ tracking needed) - size_t cancel_deferred_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type); -#endif - - // Helper to mark heap items for cancellation and update to_remove_ count - size_t cancel_heap_item_locked_(Component *component, const char *name_cstr, SchedulerItem::Type type); - uint64_t millis_(); void cleanup_(); void pop_raw_();