From f5774cc1384fd3ec79b750b49e9a0e9b34a36cac Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 17 Oct 2025 08:20:31 -1000 Subject: [PATCH] [debug] Replace std::map with struct array for ESP32 chip features (#11307) --- esphome/components/debug/debug_esp32.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/esphome/components/debug/debug_esp32.cpp b/esphome/components/debug/debug_esp32.cpp index b1dfe1bc9a..1c3dc3699b 100644 --- a/esphome/components/debug/debug_esp32.cpp +++ b/esphome/components/debug/debug_esp32.cpp @@ -11,8 +11,6 @@ #include #include -#include - #ifdef USE_ARDUINO #include #endif @@ -125,7 +123,12 @@ void DebugComponent::log_partition_info_() { uint32_t DebugComponent::get_free_heap_() { return heap_caps_get_free_size(MALLOC_CAP_INTERNAL); } -static const std::map CHIP_FEATURES = { +struct ChipFeature { + int bit; + const char *name; +}; + +static constexpr ChipFeature CHIP_FEATURES[] = { {CHIP_FEATURE_BLE, "BLE"}, {CHIP_FEATURE_BT, "BT"}, {CHIP_FEATURE_EMB_FLASH, "EMB Flash"}, @@ -170,11 +173,13 @@ void DebugComponent::get_device_info_(std::string &device_info) { esp_chip_info(&info); const char *model = ESPHOME_VARIANT; std::string features; - for (auto feature : CHIP_FEATURES) { - if (info.features & feature.first) { - features += feature.second; + + // Check each known feature bit + for (const auto &feature : CHIP_FEATURES) { + if (info.features & feature.bit) { + features += feature.name; features += ", "; - info.features &= ~feature.first; + info.features &= ~feature.bit; } } if (info.features != 0)