From 7aae946678161c63a0648935f7cbf55df4022120 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 15 Sep 2025 21:44:50 -0500 Subject: [PATCH] cleanup --- esphome/components/json/json_util.cpp | 11 ----------- esphome/components/json/json_util.h | 8 ++++---- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index 166fbcd167..51c0fcf9cb 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -44,17 +44,6 @@ bool parse_json(const std::string &data, const json_parse_t &f) { // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks) } -// JsonBuilder implementation -JsonBuilder::JsonBuilder() - : doc_( -#ifdef USE_PSRAM - &allocator_ -#else - nullptr -#endif - ) { -} - std::string JsonBuilder::serialize() { if (doc_.overflowed()) { ESP_LOGE(TAG, "JSON document overflow"); diff --git a/esphome/components/json/json_util.h b/esphome/components/json/json_util.h index 9699955133..d85e7eefe0 100644 --- a/esphome/components/json/json_util.h +++ b/esphome/components/json/json_util.h @@ -46,8 +46,6 @@ bool parse_json(const std::string &data, const json_parse_t &f); /// Builder class for creating JSON documents without lambdas class JsonBuilder { public: - JsonBuilder(); - JsonObject root() { if (!root_created_) { root_ = doc_.to(); @@ -60,9 +58,11 @@ class JsonBuilder { private: #ifdef USE_PSRAM - SpiRamAllocator allocator_; // Just a regular member on the stack! + SpiRamAllocator allocator_; // Just a regular member on the stack! + JsonDocument doc_{&allocator_}; // Initialize with allocator +#else + JsonDocument doc_; // Default initialization #endif - JsonDocument doc_; JsonObject root_; bool root_created_{false}; };