1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00

[select] Remove STL algorithm overhead to reduce flash usage

This commit is contained in:
J. Nick Koston
2025-09-25 14:20:05 -05:00
parent 74f09a2b59
commit 62a466c013
2 changed files with 6 additions and 5 deletions

View File

@@ -34,11 +34,12 @@ size_t Select::size() const {
optional<size_t> 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<size_t> Select::active_index() const {

View File

@@ -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;
}