From eea2b6b81bc3f80b58b264f057e3772b7f1b4a25 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 5 Oct 2025 19:04:50 -0500 Subject: [PATCH] [esp32_ble] Optimize string operations to reduce flash usage by 264 bytes (#11023) --- esphome/components/esp32_ble/ble.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index 64cef70de2..0c340c55cc 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -213,15 +213,17 @@ bool ESP32BLE::ble_setup_() { if (this->name_.has_value()) { name = this->name_.value(); if (App.is_name_add_mac_suffix_enabled()) { - name += "-" + get_mac_address().substr(6); + name += "-"; + name += get_mac_address().substr(6); } } else { name = App.get_name(); if (name.length() > 20) { if (App.is_name_add_mac_suffix_enabled()) { - name.erase(name.begin() + 13, name.end() - 7); // Remove characters between 13 and the mac address + // Keep first 13 chars and last 7 chars (MAC suffix), remove middle + name.erase(13, name.length() - 20); } else { - name = name.substr(0, 20); + name.resize(20); } } }