[core] Devirtualize call_loop() and mark_failed() in Component (#14083)

This commit is contained in:
J. Nick Koston
2026-02-19 08:40:23 -06:00
committed by GitHub
parent 6daca09794
commit b0085e21f7
2 changed files with 7 additions and 9 deletions
+5 -7
View File
@@ -207,7 +207,7 @@ bool Component::cancel_retry(uint32_t id) {
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
} }
void Component::call_loop() { this->loop(); } void Component::call_loop_() { this->loop(); }
void Component::call_setup() { this->setup(); } void Component::call_setup() { this->setup(); }
void Component::call_dump_config() { void Component::call_dump_config() {
this->dump_config(); this->dump_config();
@@ -258,11 +258,11 @@ void Component::call() {
case COMPONENT_STATE_SETUP: case COMPONENT_STATE_SETUP:
// State setup: Call first loop and set state to loop // State setup: Call first loop and set state to loop
this->set_component_state_(COMPONENT_STATE_LOOP); this->set_component_state_(COMPONENT_STATE_LOOP);
this->call_loop(); this->call_loop_();
break; break;
case COMPONENT_STATE_LOOP: case COMPONENT_STATE_LOOP:
// State loop: Call loop // State loop: Call loop
this->call_loop(); this->call_loop_();
break; break;
case COMPONENT_STATE_FAILED: case COMPONENT_STATE_FAILED:
// State failed: Do nothing // State failed: Do nothing
@@ -497,16 +497,14 @@ void Component::set_setup_priority(float priority) {
bool Component::has_overridden_loop() const { bool Component::has_overridden_loop() const {
#if defined(USE_HOST) || defined(CLANG_TIDY) #if defined(USE_HOST) || defined(CLANG_TIDY)
bool loop_overridden = true; return true;
bool call_loop_overridden = true;
#else #else
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpmf-conversions" #pragma GCC diagnostic ignored "-Wpmf-conversions"
bool loop_overridden = (void *) (this->*(&Component::loop)) != (void *) (&Component::loop); bool loop_overridden = (void *) (this->*(&Component::loop)) != (void *) (&Component::loop);
bool call_loop_overridden = (void *) (this->*(&Component::call_loop)) != (void *) (&Component::call_loop);
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
return loop_overridden;
#endif #endif
return loop_overridden || call_loop_overridden;
} }
PollingComponent::PollingComponent(uint32_t update_interval) : update_interval_(update_interval) {} PollingComponent::PollingComponent(uint32_t update_interval) : update_interval_(update_interval) {}
+2 -2
View File
@@ -165,7 +165,7 @@ class Component {
* For example, i2c based components can check if the remote device is responding and otherwise * For example, i2c based components can check if the remote device is responding and otherwise
* mark the component as failed. Eventually this will also enable smart status LEDs. * mark the component as failed. Eventually this will also enable smart status LEDs.
*/ */
virtual void mark_failed(); void mark_failed();
// Remove before 2026.6.0 // Remove before 2026.6.0
ESPDEPRECATED("Use mark_failed(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary " ESPDEPRECATED("Use mark_failed(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary "
@@ -286,7 +286,7 @@ class Component {
protected: protected:
friend class Application; friend class Application;
virtual void call_loop(); void call_loop_();
virtual void call_setup(); virtual void call_setup();
virtual void call_dump_config(); virtual void call_dump_config();