From 024097b6353a5a459f5d84f67c6fc1a4278ca892 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 11 Jan 2026 16:05:33 -1000 Subject: [PATCH] cleanup --- esphome/components/api/homeassistant_service.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/homeassistant_service.h b/esphome/components/api/homeassistant_service.h index dd7654b8bc..9b4f17766d 100644 --- a/esphome/components/api/homeassistant_service.h +++ b/esphome/components/api/homeassistant_service.h @@ -217,7 +217,15 @@ template class HomeAssistantServiceCallAction : public Action &value_storage, Ts... x) { dest.init(source.size()); - value_storage.init(source.size()); // Max possible, single allocation + + // Count non-static strings to allocate exact storage needed + size_t lambda_count = 0; + for (const auto &it : source) { + if (!it.value.is_static_string()) { + lambda_count++; + } + } + value_storage.init(lambda_count); for (auto &it : source) { auto &kv = dest.emplace_back();