auto-replace long functions with short names

adI = addInfo
adD = addDropdown
adO = addOption
adF = addField

before: String buffer usage: 3183 of 4037 bytes
after:    String buffer usage: 2805 of 4037 bytes
This commit is contained in:
Frank
2024-07-01 22:54:24 +02:00
parent 31a12f5098
commit 29013a3f83
3 changed files with 28 additions and 3 deletions

View File

@@ -144,22 +144,34 @@ bool oappendi(int i)
return oappend(s);
}
static bool squeezeStrings = false;
void oappendUseDeflate(bool OnOff) { squeezeStrings = OnOff; }
bool oappend(const char* txt)
{
uint16_t len = strlen(txt);
String str = squeezeStrings ? String(txt) : String("");
if (squeezeStrings) {
// simple fixed-dictionary deflate
str.replace(F("addField("), F("adF("));
str.replace(F("addDropdown("), F("adD("));
str.replace(F("addOption("), F("adO("));
str.replace(F("addInfo("), F("adI("));
}
const char* finalTxt = squeezeStrings ? str.c_str() : txt;
size_t len = strlen(finalTxt);
if ((obuf == nullptr) || (olen + len >= SETTINGS_STACK_BUF_SIZE)) { // sanity checks
if (obuf == nullptr) { USER_PRINTLN(F("oappend() error: obuf == nullptr."));
} else {
USER_PRINT(F("oappend() error: buffer full. Increase SETTINGS_STACK_BUF_SIZE for "));
USER_PRINTF("%2u bytes \t\"", len /*1 + olen + len - SETTINGS_STACK_BUF_SIZE*/);
USER_PRINT(txt);
USER_PRINT(finalTxt);
USER_PRINTLN(F("\""));
errorFlag = ERR_LOW_AJAX_MEM;
}
return false; // buffer full
}
strcpy(obuf + olen, txt);
strcpy(obuf + olen, finalTxt);
olen += len;
return true;
}