mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 18:22:22 +01:00
[select] Use const references to avoid unnecessary vector copies
This commit is contained in:
@@ -28,12 +28,12 @@ bool Select::has_option(const std::string &option) const { return this->index_of
|
||||
bool Select::has_index(size_t index) const { return index < this->size(); }
|
||||
|
||||
size_t Select::size() const {
|
||||
auto options = traits.get_options();
|
||||
const auto &options = traits.get_options();
|
||||
return options.size();
|
||||
}
|
||||
|
||||
optional<size_t> Select::index_of(const std::string &option) const {
|
||||
auto options = traits.get_options();
|
||||
const auto &options = traits.get_options();
|
||||
auto it = std::find(options.begin(), options.end(), option);
|
||||
if (it == options.end()) {
|
||||
return {};
|
||||
@@ -51,7 +51,7 @@ optional<size_t> Select::active_index() const {
|
||||
|
||||
optional<std::string> Select::at(size_t index) const {
|
||||
if (this->has_index(index)) {
|
||||
auto options = traits.get_options();
|
||||
const auto &options = traits.get_options();
|
||||
return options.at(index);
|
||||
} else {
|
||||
return {};
|
||||
|
@@ -45,7 +45,7 @@ void SelectCall::perform() {
|
||||
auto *parent = this->parent_;
|
||||
const auto *name = parent->get_name().c_str();
|
||||
const auto &traits = parent->traits;
|
||||
auto options = traits.get_options();
|
||||
const auto &options = traits.get_options();
|
||||
|
||||
if (this->operation_ == SELECT_OP_NONE) {
|
||||
ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", name);
|
||||
|
Reference in New Issue
Block a user