mirror of
https://github.com/esphome/esphome.git
synced 2026-02-25 04:45:29 -07:00
[core] Devirtualize call_loop() and mark_failed() in Component (#14083)
This commit is contained in:
@@ -207,7 +207,7 @@ bool Component::cancel_retry(uint32_t id) {
|
||||
#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_dump_config() {
|
||||
this->dump_config();
|
||||
@@ -258,11 +258,11 @@ void Component::call() {
|
||||
case COMPONENT_STATE_SETUP:
|
||||
// State setup: Call first loop and set state to loop
|
||||
this->set_component_state_(COMPONENT_STATE_LOOP);
|
||||
this->call_loop();
|
||||
this->call_loop_();
|
||||
break;
|
||||
case COMPONENT_STATE_LOOP:
|
||||
// State loop: Call loop
|
||||
this->call_loop();
|
||||
this->call_loop_();
|
||||
break;
|
||||
case COMPONENT_STATE_FAILED:
|
||||
// State failed: Do nothing
|
||||
@@ -497,16 +497,14 @@ void Component::set_setup_priority(float priority) {
|
||||
|
||||
bool Component::has_overridden_loop() const {
|
||||
#if defined(USE_HOST) || defined(CLANG_TIDY)
|
||||
bool loop_overridden = true;
|
||||
bool call_loop_overridden = true;
|
||||
return true;
|
||||
#else
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpmf-conversions"
|
||||
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
|
||||
return loop_overridden;
|
||||
#endif
|
||||
return loop_overridden || call_loop_overridden;
|
||||
}
|
||||
|
||||
PollingComponent::PollingComponent(uint32_t update_interval) : update_interval_(update_interval) {}
|
||||
|
||||
@@ -165,7 +165,7 @@ class Component {
|
||||
* 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.
|
||||
*/
|
||||
virtual void mark_failed();
|
||||
void mark_failed();
|
||||
|
||||
// Remove before 2026.6.0
|
||||
ESPDEPRECATED("Use mark_failed(LOG_STR(\"static string literal\")) instead. Do NOT use .c_str() from temporary "
|
||||
@@ -286,7 +286,7 @@ class Component {
|
||||
protected:
|
||||
friend class Application;
|
||||
|
||||
virtual void call_loop();
|
||||
void call_loop_();
|
||||
virtual void call_setup();
|
||||
virtual void call_dump_config();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user