1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-27 05:03:48 +00:00

[api] Eliminate heap allocations when populating repeated fields from containers (#9948)

This commit is contained in:
J. Nick Koston
2025-07-29 12:41:37 -10:00
committed by GitHub
parent daccaf36a7
commit 76d33308d9
13 changed files with 255 additions and 101 deletions

View File

@@ -5,6 +5,13 @@
#include <set>
namespace esphome {
#ifdef USE_API
namespace api {
class APIConnection;
} // namespace api
#endif
namespace light {
/// This class is used to represent the capabilities of a light.
@@ -52,6 +59,16 @@ class LightTraits {
void set_max_mireds(float max_mireds) { this->max_mireds_ = max_mireds; }
protected:
#ifdef USE_API
// The API connection is a friend class to access internal methods
friend class api::APIConnection;
// This method returns a reference to the internal color modes set.
// It is used by the API to avoid copying data when encoding messages.
// Warning: Do not use this method outside of the API connection code.
// It returns a reference to internal data that can be invalidated.
const std::set<ColorMode> &get_supported_color_modes_for_api_() const { return this->supported_color_modes_; }
#endif
std::set<ColorMode> supported_color_modes_{};
float min_mireds_{0};
float max_mireds_{0};