From 8fb69826f980c143f52dac0405d56e7150ece332 Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 8 Jun 2026 20:54:43 +0200 Subject: [PATCH] comments --- src/core/emsesp.cpp | 9 ++++----- src/core/helpers.cpp | 5 +---- src/core/shuntingYard.cpp | 8 +++----- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index c536000e9..9753a5d38 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -51,13 +51,13 @@ uint32_t EMSESP::last_fetch_ = 0; AsyncWebServer webServer(80); #if defined(EMSESP_STANDALONE) -FS dummyFS; -auto& fsRef = dummyFS; +FS dummyFS; +auto & fsRef = dummyFS; #else -auto& fsRef = LittleFS; +auto & fsRef = LittleFS; #endif -ESP32React EMSESP::esp32React(&webServer, &fsRef); +ESP32React EMSESP::esp32React(&webServer, &fsRef); WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); WebCustomizationService EMSESP::webCustomizationService = WebCustomizationService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); WebSchedulerService EMSESP::webSchedulerService = WebSchedulerService(&webServer, &fsRef, EMSESP::esp32React.getSecurityManager()); @@ -919,7 +919,6 @@ std::string EMSESP::pretty_telegram(const std::shared_ptr & tele } } - // Optimized: Use stack buffer and build string once to avoid multiple temporary allocations char buf[250]; if (telegram->operation == Telegram::Operation::RX_READ) { auto pos = snprintf(buf, diff --git a/src/core/helpers.cpp b/src/core/helpers.cpp index 8098f93d8..52d37b50b 100644 --- a/src/core/helpers.cpp +++ b/src/core/helpers.cpp @@ -34,7 +34,6 @@ char * Helpers::hextoa(char * result, const uint8_t value) { } // same as hextoa but uses to a hex std::string -// Optimized: Avoid string concatenation to reduce temporary allocations std::string Helpers::hextoa(const uint8_t value, bool prefix) { if (prefix) { char buf[5]; // "0x" + 2 hex chars + null @@ -60,7 +59,6 @@ char * Helpers::hextoa(char * result, const uint16_t value) { } // same as above but to a hex string -// Optimized: Avoid string concatenation to reduce temporary allocations std::string Helpers::hextoa(const uint16_t value, bool prefix) { if (prefix) { char buf[7]; // "0x" + 4 hex chars + null @@ -114,7 +112,6 @@ char * Helpers::ultostr(char * ptr, uint32_t value, const uint8_t base) { // fast itoa returning a std::string // http://www.strudel.org.uk/itoa/ -// Optimized: Use stack buffer to avoid heap allocation, then create string once std::string Helpers::itoa(int16_t value) { // int16_t max: -32768 to 32767 = max 6 chars + null char buf[8]; @@ -140,7 +137,7 @@ std::string Helpers::itoa(int16_t value) { /* * fast itoa * written by Lukás Chmela, Released under GPLv3. http://www.strudel.org.uk/itoa/ version 0.4 - * optimized for ESP32 + * optimized for ESP32 for EMS-ESP */ char * Helpers::itoa(int32_t value, char * result, const uint8_t base) { // check that the base if valid diff --git a/src/core/shuntingYard.cpp b/src/core/shuntingYard.cpp index 9f833892a..7041ca49f 100644 --- a/src/core/shuntingYard.cpp +++ b/src/core/shuntingYard.cpp @@ -27,7 +27,7 @@ namespace emsesp { -// find tokens - optimized to reduce string allocations +// find tokens std::deque exprToTokens(const std::string & expr) { std::deque tokens; @@ -231,7 +231,7 @@ std::deque exprToTokens(const std::string & expr) { return tokens; } -// sort tokens to RPN form - optimized for memory usage +// sort tokens to RPN form std::deque shuntingYard(const std::deque & tokens) { std::deque queue; std::vector stack; @@ -347,7 +347,6 @@ bool isnum(const std::string & s) { std::string commands(std::string & expr, bool quotes) { auto expr_new = Helpers::toLower(expr); for (uint8_t device = 0; device < EMSdevice::DeviceType::UNKNOWN; device++) { - // Optimized: build string with reserve to avoid temporary allocations std::string d; d.reserve(32); // typical device name length + "/" d = EMSdevice::device_type_2_device_name(device); @@ -374,8 +373,7 @@ std::string commands(std::string & expr, bool quotes) { JsonDocument doc_in; JsonObject output = doc_out.to(); JsonObject input = doc_in.to(); - // Optimized: use stack buffer for small strings to avoid heap allocation - char cmd_s[COMMAND_MAX_LENGTH + 5]; // "api/" prefix + cmd + char cmd_s[COMMAND_MAX_LENGTH + 5]; // "api/" prefix + cmd snprintf(cmd_s, sizeof(cmd_s), "api/%s", cmd); auto return_code = Command::process(cmd_s, true, input, output);