Optimize get_config_hash to avoid repeated snprintf calls

Check if hash string is already formatted before calling snprintf,
since static variables in BSS are zero-initialized.
This commit is contained in:
David Woodhouse
2025-12-11 22:53:03 +09:00
parent 54ed6154eb
commit 58fddeb74f

View File

@@ -34,7 +34,9 @@ static uintptr_t build_time = (uintptr_t) &ESPHOME_BUILD_TIME;
const char *get_config_hash() {
static char hash_str[9];
snprintf(hash_str, sizeof(hash_str), "%08x", (uint32_t) config_hash);
if (!hash_str[0]) {
snprintf(hash_str, sizeof(hash_str), "%08x", (uint32_t) config_hash);
}
return hash_str;
}