mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 09:08:41 +00:00
Remove get_loop_component_start_time wrapper, use forward-declared App directly
The wrapper added a function call indirection on every filter invocation that the compiler cannot inline without LTO. Forward-declaring Application and App lets the template body call App.get_loop_component_start_time() directly — the method is inline in application.h which is included by main.cpp where the template is instantiated.
This commit is contained in:
@@ -222,8 +222,6 @@ MultiplyFilter::MultiplyFilter(TemplatableValue<float> multiplier) : multiplier_
|
||||
|
||||
optional<float> MultiplyFilter::new_value(float value) { return value * this->multiplier_.value(); }
|
||||
|
||||
uint32_t get_loop_component_start_time() { return App.get_loop_component_start_time(); }
|
||||
|
||||
// ValueListFilter helper (non-template, shared by all ValueListFilter<N> instantiations)
|
||||
bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue<float> *values, size_t count) {
|
||||
int8_t accuracy = parent->get_accuracy_decimals();
|
||||
|
||||
@@ -332,8 +332,14 @@ class MultiplyFilter : public Filter {
|
||||
/// Non-template helper for value matching (implementation in filter.cpp)
|
||||
bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue<float> *values, size_t count);
|
||||
|
||||
/// Non-template helper to get cached loop start time (avoids circular include of application.h)
|
||||
uint32_t get_loop_component_start_time();
|
||||
} // namespace esphome::sensor
|
||||
// Forward declaration — avoids circular include of application.h.
|
||||
// Template bodies are only instantiated in main.cpp where Application is fully defined.
|
||||
namespace esphome {
|
||||
class Application;
|
||||
extern Application App;
|
||||
} // namespace esphome
|
||||
namespace esphome::sensor {
|
||||
|
||||
/** Base class for filters that compare sensor values against a fixed list of configured values.
|
||||
*
|
||||
@@ -389,7 +395,7 @@ template<size_t N> class ThrottleWithPriorityFilter : public ValueListFilter<N>
|
||||
: ValueListFilter<N>(prioritized_values), min_time_between_inputs_(min_time_between_inputs) {}
|
||||
|
||||
optional<float> new_value(float value) override {
|
||||
const uint32_t now = get_loop_component_start_time();
|
||||
const uint32_t now = App.get_loop_component_start_time();
|
||||
if (this->last_input_ == 0 || now - this->last_input_ >= this->min_time_between_inputs_ ||
|
||||
this->value_matches_any_(value)) {
|
||||
this->last_input_ = now;
|
||||
|
||||
Reference in New Issue
Block a user