From 7a8b2feec62b4bb8c5ca45e8c1848ec124e404ea Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 2 Aug 2025 15:56:47 -1000 Subject: [PATCH] [core] Optimize Application::pre_setup() to reduce duplicate MAC address operations --- esphome/core/application.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/esphome/core/application.h b/esphome/core/application.h index b7824a254b..c60c9a3d66 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -101,12 +101,9 @@ class Application { arch_init(); this->name_add_mac_suffix_ = name_add_mac_suffix; if (name_add_mac_suffix) { - this->name_ = name + "-" + get_mac_address().substr(6); - if (friendly_name.empty()) { - this->friendly_name_ = ""; - } else { - this->friendly_name_ = friendly_name + " " + get_mac_address().substr(6); - } + const std::string mac_suffix = get_mac_address().substr(6); + this->name_ = name + "-" + mac_suffix; + this->friendly_name_ = friendly_name.empty() ? "" : friendly_name + " " + mac_suffix; } else { this->name_ = name; this->friendly_name_ = friendly_name;