mirror of
https://github.com/esphome/esphome.git
synced 2025-10-24 20:53:48 +01:00
[core] Convert entity vectors to static allocation for reduced memory usage (#10018)
This commit is contained in:
@@ -91,6 +91,42 @@ template<> constexpr int64_t byteswap(int64_t n) { return __builtin_bswap64(n);
|
||||
|
||||
///@}
|
||||
|
||||
/// @name Container utilities
|
||||
///@{
|
||||
|
||||
/// Minimal static vector - saves memory by avoiding std::vector overhead
|
||||
template<typename T, size_t N> class StaticVector {
|
||||
public:
|
||||
using value_type = T;
|
||||
using iterator = typename std::array<T, N>::iterator;
|
||||
using const_iterator = typename std::array<T, N>::const_iterator;
|
||||
|
||||
private:
|
||||
std::array<T, N> data_{};
|
||||
size_t count_{0};
|
||||
|
||||
public:
|
||||
// Minimal vector-compatible interface - only what we actually use
|
||||
void push_back(const T &value) {
|
||||
if (count_ < N) {
|
||||
data_[count_++] = value;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const { return count_; }
|
||||
|
||||
T &operator[](size_t i) { return data_[i]; }
|
||||
const T &operator[](size_t i) const { return data_[i]; }
|
||||
|
||||
// For range-based for loops
|
||||
iterator begin() { return data_.begin(); }
|
||||
iterator end() { return data_.begin() + count_; }
|
||||
const_iterator begin() const { return data_.begin(); }
|
||||
const_iterator end() const { return data_.begin() + count_; }
|
||||
};
|
||||
|
||||
///@}
|
||||
|
||||
/// @name Mathematics
|
||||
///@{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user