mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 10:42:21 +01:00
[core] Reduce flash usage by refactoring looping component partitioning (#10652)
This commit is contained in:
@@ -361,20 +361,19 @@ void Application::calculate_looping_components_() {
|
|||||||
// Add all components with loop override that aren't already LOOP_DONE
|
// Add all components with loop override that aren't already LOOP_DONE
|
||||||
// Some components (like logger) may call disable_loop() during initialization
|
// Some components (like logger) may call disable_loop() during initialization
|
||||||
// before setup runs, so we need to respect their LOOP_DONE state
|
// before setup runs, so we need to respect their LOOP_DONE state
|
||||||
for (auto *obj : this->components_) {
|
this->add_looping_components_by_state_(false);
|
||||||
if (obj->has_overridden_loop() &&
|
|
||||||
(obj->get_component_state() & COMPONENT_STATE_MASK) != COMPONENT_STATE_LOOP_DONE) {
|
|
||||||
this->looping_components_.push_back(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->looping_components_active_end_ = this->looping_components_.size();
|
this->looping_components_active_end_ = this->looping_components_.size();
|
||||||
|
|
||||||
// Then add any components that are already LOOP_DONE to the inactive section
|
// Then add any components that are already LOOP_DONE to the inactive section
|
||||||
// This handles components that called disable_loop() during initialization
|
// This handles components that called disable_loop() during initialization
|
||||||
|
this->add_looping_components_by_state_(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::add_looping_components_by_state_(bool match_loop_done) {
|
||||||
for (auto *obj : this->components_) {
|
for (auto *obj : this->components_) {
|
||||||
if (obj->has_overridden_loop() &&
|
if (obj->has_overridden_loop() &&
|
||||||
(obj->get_component_state() & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) {
|
((obj->get_component_state() & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) == match_loop_done) {
|
||||||
this->looping_components_.push_back(obj);
|
this->looping_components_.push_back(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -431,6 +431,7 @@ class Application {
|
|||||||
void register_component_(Component *comp);
|
void register_component_(Component *comp);
|
||||||
|
|
||||||
void calculate_looping_components_();
|
void calculate_looping_components_();
|
||||||
|
void add_looping_components_by_state_(bool match_loop_done);
|
||||||
|
|
||||||
// These methods are called by Component::disable_loop() and Component::enable_loop()
|
// These methods are called by Component::disable_loop() and Component::enable_loop()
|
||||||
// Components should not call these directly - use this->disable_loop() or this->enable_loop()
|
// Components should not call these directly - use this->disable_loop() or this->enable_loop()
|
||||||
|
Reference in New Issue
Block a user