From 58fddeb74f9215a7d7c8ff8dd935727cbdf0e5d8 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 11 Dec 2025 22:53:03 +0900 Subject: [PATCH] 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. --- esphome/core/buildinfo.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/core/buildinfo.cpp b/esphome/core/buildinfo.cpp index 839bee9857..dd07fa6f6c 100644 --- a/esphome/core/buildinfo.cpp +++ b/esphome/core/buildinfo.cpp @@ -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; }