From fe8b33df72de8d1de8a514132d91bc6687a4290b Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 18 Oct 2024 12:18:19 +0200 Subject: [PATCH] optimize ArduinoJson serialization: avoid copies of strings --- src/ha.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ha.h b/src/ha.h index 0299def..f1840c1 100644 --- a/src/ha.h +++ b/src/ha.h @@ -88,7 +88,7 @@ namespace Ha { const char* entityCategory = nullptr; const char* deviceClass = nullptr; const char* name = nullptr; - char* id = nullptr; + const char* id = nullptr; const char* type = nullptr; char configTopic[TOPIC_SIZE]; JsonPairs jsonBooleans; @@ -98,7 +98,7 @@ namespace Ha { static List components; bool multiValueComponent = false; - Component(const char* name, const char* id, const char* type) : name(name), id((char*)id), type(type) { + Component(const char* name, const char* id, const char* type) : name(name), id(id), type(type) { components.add(this); } @@ -134,7 +134,7 @@ namespace Ha { if (deviceClass) jsonDoc["device_class"] = deviceClass; jsonDoc["name"] = name; buildUniqueId(); - jsonDoc["unique_id"] = uniqueId; + jsonDoc["unique_id"] = (const char*)uniqueId; buildConfigTopic(); buildComponentConfig(jsonDoc); @@ -276,7 +276,7 @@ namespace Ha { virtual void buildCommandConfig(JsonDocument& jsonDoc) = 0; void buildComponentConfig(JsonDocument& jsonDoc) override { - jsonDoc["command_topic"] = commandTopic; + jsonDoc["command_topic"] = (const char*)commandTopic; if (retain) jsonDoc["retain"] = true; buildCommandConfig(jsonDoc); } @@ -308,7 +308,7 @@ namespace Ha { protected: Component* cmp; void buildConfig(JsonDocument& jsonDoc) { - if (stateTopic[0]) jsonDoc["state_topic"] = stateTopic; + if (stateTopic[0]) jsonDoc["state_topic"] = (const char*)stateTopic; } };