From 295b31780949bce44e19db16831cf77252b64eda Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 11 Dec 2025 22:54:19 +0900 Subject: [PATCH] Optimize get_build_time_string to avoid repeated formatting Apply same concurrency fix as get_config_hash to prevent race conditions when multiple threads access the function. --- esphome/core/buildinfo.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/core/buildinfo.cpp b/esphome/core/buildinfo.cpp index dd07fa6f6c..58129c43b5 100644 --- a/esphome/core/buildinfo.cpp +++ b/esphome/core/buildinfo.cpp @@ -44,9 +44,11 @@ time_t get_build_time() { return (time_t) build_time; } const char *get_build_time_string() { static char time_str[32]; - time_t bt = get_build_time(); - struct tm *tm_info = localtime(&bt); - strftime(time_str, sizeof(time_str), "%b %d %Y, %H:%M:%S", tm_info); + if (!time_str[0]) { + time_t bt = get_build_time(); + struct tm *tm_info = localtime(&bt); + strftime(time_str, sizeof(time_str), "%b %d %Y, %H:%M:%S", tm_info); + } return time_str; }