Restore template wrapper as protected register_component_

Rename the non-template to register_component_impl_ and add
a protected template register_component_ that wraps it. This
preserves the compiler optimization behavior (isra clones)
while keeping the method inaccessible to external components.

Co-Authored-By: J. Nick Koston <nick@koston.org>
This commit is contained in:
J. Nick Koston
2026-02-27 21:31:06 -10:00
parent 6d1a40f210
commit ebde654259
2 changed files with 9 additions and 2 deletions

View File

@@ -79,7 +79,7 @@ static void insertion_sort_by_priority(Iterator first, Iterator last) {
}
}
void Application::register_component_(Component *comp) { this->components_.push_back(comp); }
void Application::register_component_impl_(Component *comp) { this->components_.push_back(comp); }
void Application::setup() {
ESP_LOGI(TAG, "Running through setup()");
ESP_LOGV(TAG, "Sorting components by setup priority");

View File

@@ -521,7 +521,14 @@ class Application {
#endif
#endif
__attribute__((noinline)) void register_component_(Component *comp);
/// Register a component - only callable from codegen-generated setup() via friend access.
template<class C> C *register_component_(C *c) {
static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
this->register_component_impl_((Component *) c);
return c;
}
void register_component_impl_(Component *comp);
void calculate_looping_components_();
void add_looping_components_by_state_(bool match_loop_done);