mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
[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:
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user