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:
@@ -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 {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user