[combination] Use FixedVector for sensor sources to eliminate realloc machinery

The source count is known at config time, so pre-allocate with
FixedVector::init() instead of using std::vector which pulls in
_M_realloc_insert template instantiation code.
This commit is contained in:
J. Nick Koston
2026-03-18 21:19:22 -10:00
parent 5b8acaa7c0
commit 04552e240e
2 changed files with 6 additions and 2 deletions
+3 -2
View File
@@ -1,10 +1,10 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/components/sensor/sensor.h"
#include <functional>
#include <vector>
namespace esphome {
namespace combination {
@@ -42,6 +42,7 @@ class CombinationNoParameterComponent : public CombinationComponent {
// Base class for opertions that require one parameter to compute the combination
class CombinationOneParameterComponent : public CombinationComponent {
public:
void set_source_count(size_t count) { this->sensor_sources_.init(count); }
void add_source(Sensor *sensor, std::function<float(float)> const &compute);
void add_source(Sensor *sensor, float value);
@@ -55,7 +56,7 @@ class CombinationOneParameterComponent : public CombinationComponent {
};
protected:
std::vector<SensorSource> sensor_sources_;
FixedVector<SensorSource> sensor_sources_;
};
class KalmanCombinationComponent : public CombinationOneParameterComponent {
+3
View File
@@ -180,6 +180,9 @@ async def to_code(config):
if proces_std_dev := config.get(CONF_PROCESS_STD_DEV):
cg.add(var.set_process_std_dev(proces_std_dev))
if config[CONF_TYPE] in (CONF_KALMAN, CONF_LINEAR):
cg.add(var.set_source_count(len(config[CONF_SOURCES])))
for source_conf in config[CONF_SOURCES]:
source = await cg.get_variable(source_conf[CONF_SOURCE])
if config[CONF_TYPE] == CONF_KALMAN: