From 62a466c0136d1ae48c668b5b1054c9e3aea6e3a4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 25 Sep 2025 14:20:05 -0500 Subject: [PATCH] [select] Remove STL algorithm overhead to reduce flash usage --- esphome/components/select/select.cpp | 9 +++++---- esphome/components/select/select_call.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index beb72aa320..16e8288ca1 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -34,11 +34,12 @@ size_t Select::size() const { optional Select::index_of(const std::string &option) const { const auto &options = traits.get_options(); - auto it = std::find(options.begin(), options.end(), option); - if (it == options.end()) { - return {}; + for (size_t i = 0; i < options.size(); i++) { + if (options[i] == option) { + return i; + } } - return std::distance(options.begin(), it); + return {}; } optional Select::active_index() const { diff --git a/esphome/components/select/select_call.cpp b/esphome/components/select/select_call.cpp index a8272f8622..dd398b4052 100644 --- a/esphome/components/select/select_call.cpp +++ b/esphome/components/select/select_call.cpp @@ -107,7 +107,7 @@ void SelectCall::perform() { } } - if (std::find(options.begin(), options.end(), target_value) == options.end()) { + if (!parent->has_option(target_value)) { ESP_LOGW(TAG, "'%s' - Option %s is not a valid option", name, target_value.c_str()); return; }