From 6f1185011f68a3989b5f1364f4d269961bb63050 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 5 Jan 2026 09:04:12 -1000 Subject: [PATCH] [bthome_mithermometer] Reduce heap allocations with stack-based string formatting --- esphome/components/bthome_mithermometer/bthome_ble.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/bthome_mithermometer/bthome_ble.cpp b/esphome/components/bthome_mithermometer/bthome_ble.cpp index 762fc68b037..d1c51658962 100644 --- a/esphome/components/bthome_mithermometer/bthome_ble.cpp +++ b/esphome/components/bthome_mithermometer/bthome_ble.cpp @@ -4,6 +4,7 @@ #include "esphome/core/log.h" #include +#include #ifdef USE_ESP32 @@ -12,14 +13,14 @@ namespace bthome_mithermometer { static const char *const TAG = "bthome_mithermometer"; -static const char *format_mac_address(char *buffer, uint64_t address) { +static const char *format_mac_address(std::span buffer, uint64_t address) { std::array mac{}; for (size_t i = 0; i < MAC_ADDRESS_SIZE; i++) { mac[i] = (address >> ((MAC_ADDRESS_SIZE - 1 - i) * 8)) & 0xFF; } - format_mac_addr_upper(mac.data(), buffer); - return buffer; + format_mac_addr_upper(mac.data(), buffer.data()); + return buffer.data(); } static bool get_bthome_value_length(uint8_t obj_type, size_t &value_length) {