Skip to content

Commit

Permalink
Improve Vector search for char* argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Apr 6, 2024
1 parent 72e81a2 commit 20e64e5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/include/FlashString/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,30 @@ template <class ObjectType> class Vector : public Object<Vector<ObjectType>, con

using Object<Vector<ObjectType>, const ObjectType*>::indexOf;

template <typename ValueType, typename T = ObjectType>
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const ValueType& value,
template <typename T = ObjectType>
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const char* value,
bool ignoreCase = true) const
{
if(!ignoreCase) {
return Object<Vector<String>, const String*>::indexOf(value);
auto dataptr = this->data();
auto len = this->length();
auto clen = strlen(value);
for(unsigned i = 0; i < len; ++i) {
if(unsafeValueAt(dataptr, i).equals(value, clen, ignoreCase)) {
return i;
}
}

return -1;
}

template <typename ValueType, typename T = ObjectType>
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const ValueType& value,
bool ignoreCase = true) const
{
auto dataptr = this->data();
auto len = this->length();
for(unsigned i = 0; i < len; ++i) {
if(unsafeValueAt(dataptr, i).equalsIgnoreCase(value)) {
if(unsafeValueAt(dataptr, i).equals(value, ignoreCase)) {
return i;
}
}
Expand Down

0 comments on commit 20e64e5

Please sign in to comment.