From 5a4c64abf29c8142a7ca5b003a395ae8cb95514f Mon Sep 17 00:00:00 2001 From: TD-er Date: Wed, 15 Nov 2023 13:29:12 +0100 Subject: [PATCH] [ESP8266] Change default platform to not using 2nd heap --- platformio_esp82xx_base.ini | 8 +++---- src/src/DataStructs/Web_StreamingBuffer.cpp | 12 ++++++---- src/src/WebServer/Rules.cpp | 26 +++++++++------------ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/platformio_esp82xx_base.ini b/platformio_esp82xx_base.ini index 32a5d1d52..91b71005c 100644 --- a/platformio_esp82xx_base.ini +++ b/platformio_esp82xx_base.ini @@ -4,10 +4,10 @@ [regular_platform] -build_flags = ${core_stage_2ndheap.build_flags} -platform = ${core_stage_2ndheap.platform} -platform_packages = ${core_stage_2ndheap.platform_packages} -lib_ignore = ${core_stage_2ndheap.lib_ignore} +build_flags = ${core_stage.build_flags} +platform = ${core_stage.platform} +platform_packages = ${core_stage.platform_packages} +lib_ignore = ${core_stage.lib_ignore} [regular_platform_alt_wifi] build_flags = ${core_2_7_4_alt_wifi.build_flags} diff --git a/src/src/DataStructs/Web_StreamingBuffer.cpp b/src/src/DataStructs/Web_StreamingBuffer.cpp index 7ca0ccd0e..fa8b973cc 100644 --- a/src/src/DataStructs/Web_StreamingBuffer.cpp +++ b/src/src/DataStructs/Web_StreamingBuffer.cpp @@ -148,14 +148,16 @@ Web_StreamingBuffer& Web_StreamingBuffer::addString(const String& a) { unsigned int pos = 0; while (pos < length) { - if (flush_step == 0) { + if (flush_step <= 0) { flush(); flush_step = CHUNKED_BUFFER_SIZE; } else { - // Just copy per byte instead of using substring as substring needs to allocate memory. - this->buf += a[pos]; - ++pos; - --flush_step; + const int remaining = length - pos; + const int fetchLength = flush_step >= remaining ? remaining : flush_step; + const char* ch = a.begin() + pos; + this->buf.concat(ch, static_cast(fetchLength)); + pos += fetchLength; + flush_step -= fetchLength; } } return *this; diff --git a/src/src/WebServer/Rules.cpp b/src/src/WebServer/Rules.cpp index f8316ed6b..e526ccf0f 100644 --- a/src/src/WebServer/Rules.cpp +++ b/src/src/WebServer/Rules.cpp @@ -33,16 +33,15 @@ void handle_rules() { if (!isLoggedIn() || !Settings.UseRules) { return; } navMenuIndex = MENU_INDEX_RULES; - const uint8_t rulesSet = getFormItemInt(F("set"), 1); + const int rulesSet = getFormItemInt(F("set"), 1); - # if defined(ESP8266) - String fileName = F("rules"); - # endif // if defined(ESP8266) - # if defined(ESP32) - String fileName = F("/rules"); - # endif // if defined(ESP32) - fileName += rulesSet; - fileName += F(".txt"); + const String fileName = strformat( + #ifdef ESP8266 + F("rules%d.txt") + #else + F("/rules%d.txt") + #endif + , rulesSet); String error; @@ -50,9 +49,7 @@ void handle_rules() { if (!fileExists(fileName)) { if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("Rules : Create new file: "); - log += fileName; - addLogMove(LOG_LEVEL_INFO, log); + addLogMove(LOG_LEVEL_INFO, concat(F("Rules : Create new file: %s"), fileName)); } fs::File f = tryOpenFile(fileName, "w"); @@ -74,14 +71,13 @@ void handle_rules() { addHtml(F("
")); { // Place combo box in its own scope to release these arrays as soon as possible - uint8_t choice = rulesSet; + int choice = rulesSet; String options[RULESETS_MAX]; int optionValues[RULESETS_MAX]; for (uint8_t x = 0; x < RULESETS_MAX; x++) { - options[x] = F("Rules Set "); - options[x] += x + 1; + options[x] = concat(F("Rules Set "), x+1); optionValues[x] = x + 1; }