[select] Inline size() and use the length based index_of in has_option

This commit is contained in:
J. Nick Koston
2026-08-22 00:57:25 -05:00
parent 75988f0747
commit a992162698
2 changed files with 2 additions and 7 deletions
-5
View File
@@ -32,11 +32,6 @@ void Select::publish_state(size_t index) {
#endif #endif
} }
size_t Select::size() const {
const auto &options = traits.get_options();
return options.size();
}
optional<size_t> Select::index_of(const char *option, size_t len) const { optional<size_t> Select::index_of(const char *option, size_t len) const {
const auto &options = traits.get_options(); const auto &options = traits.get_options();
for (size_t i = 0; i < options.size(); i++) { for (size_t i = 0; i < options.size(); i++) {
+2 -2
View File
@@ -48,14 +48,14 @@ class Select : public EntityBase {
SelectCall make_call() { return SelectCall(this); } SelectCall make_call() { return SelectCall(this); }
/// Return whether this select component contains the provided option. /// Return whether this select component contains the provided option.
bool has_option(const std::string &option) const { return this->index_of(option.c_str()).has_value(); } bool has_option(const std::string &option) const { return this->index_of(option).has_value(); }
bool has_option(const char *option) const { return this->index_of(option).has_value(); } bool has_option(const char *option) const { return this->index_of(option).has_value(); }
/// Return whether this select component contains the provided index offset. /// Return whether this select component contains the provided index offset.
bool has_index(size_t index) const { return index < this->size(); } bool has_index(size_t index) const { return index < this->size(); }
/// Return the number of options in this select component. /// Return the number of options in this select component.
size_t size() const; size_t size() const { return this->traits.get_options().size(); }
/// Find the (optional) index offset of the provided option value. /// Find the (optional) index offset of the provided option value.
optional<size_t> index_of(const char *option, size_t len) const; optional<size_t> index_of(const char *option, size_t len) const;