tweak naming

This commit is contained in:
J. Nick Koston
2025-11-20 07:22:27 -06:00
parent 177026d8c4
commit 946f8deb3d
2 changed files with 9 additions and 9 deletions

View File

@@ -436,7 +436,7 @@ void APIServer::add_state_subscription_(const char *entity_id, const char *attri
std::function<void(std::string)> f, bool once) {
this->state_subs_.push_back(HomeAssistantStateSubscription{
.entity_id_ = entity_id, .attribute_ = attribute, .callback_ = std::move(f), .once_ = once,
// entity_id_copy_ and attribute_copy_ remain nullptr (no heap allocation)
// entity_id_dynamic_storage_ and attribute_dynamic_storage_ remain nullptr (no heap allocation)
});
}
@@ -445,12 +445,12 @@ void APIServer::add_state_subscription_(std::string entity_id, optional<std::str
std::function<void(std::string)> f, bool once) {
HomeAssistantStateSubscription sub;
// Allocate heap storage for the strings
sub.entity_id_copy_ = std::make_unique<std::string>(std::move(entity_id));
sub.entity_id_ = sub.entity_id_copy_->c_str();
sub.entity_id_dynamic_storage_ = std::make_unique<std::string>(std::move(entity_id));
sub.entity_id_ = sub.entity_id_dynamic_storage_->c_str();
if (attribute.has_value()) {
sub.attribute_copy_ = std::make_unique<std::string>(std::move(attribute.value()));
sub.attribute_ = sub.attribute_copy_->c_str();
sub.attribute_dynamic_storage_ = std::make_unique<std::string>(std::move(attribute.value()));
sub.attribute_ = sub.attribute_dynamic_storage_->c_str();
} else {
sub.attribute_ = nullptr;
}

View File

@@ -159,10 +159,10 @@ class APIServer : public Component, public Controller {
std::function<void(std::string)> callback_;
bool once_;
// Storage for external components using std::string API (custom_api_device.h)
// These are only allocated when using the std::string overload
std::unique_ptr<std::string> entity_id_copy_;
std::unique_ptr<std::string> attribute_copy_;
// Dynamic storage for external components using std::string API (custom_api_device.h)
// These are only allocated when using the std::string overload (nullptr for const char* overload)
std::unique_ptr<std::string> entity_id_dynamic_storage_;
std::unique_ptr<std::string> attribute_dynamic_storage_;
};
// New const char* overload (for internal components - zero allocation)