Skip to content

Commit 20e64e5

Browse files
author
mikee47
committed
Improve Vector search for char* argument
1 parent 72e81a2 commit 20e64e5

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/include/FlashString/Vector.hpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,30 @@ template <class ObjectType> class Vector : public Object<Vector<ObjectType>, con
113113

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

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

129+
return -1;
130+
}
131+
132+
template <typename ValueType, typename T = ObjectType>
133+
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const ValueType& value,
134+
bool ignoreCase = true) const
135+
{
124136
auto dataptr = this->data();
125137
auto len = this->length();
126138
for(unsigned i = 0; i < len; ++i) {
127-
if(unsafeValueAt(dataptr, i).equalsIgnoreCase(value)) {
139+
if(unsafeValueAt(dataptr, i).equals(value, ignoreCase)) {
128140
return i;
129141
}
130142
}

0 commit comments

Comments
 (0)