Skip to content

Commit 86015f4

Browse files
Simplify String::remove(unsigned int)
Previously, this method calculated the length of the string from the given index onwards. However, the other remove() method called already contains code for this calculation, which is used when the count passed in is too big. This means we can just pass in a very big count that is guaranteed to point past the end of the string, shrinking the remove method by a few bytes.
1 parent 2068f88 commit 86015f4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

hardware/arduino/avr/cores/arduino/WString.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,10 @@ void String::replace(const String& find, const String& replace)
684684
}
685685

686686
void String::remove(unsigned int index){
687-
int count = len - index;
688-
remove(index, count);
687+
// Pass the biggest integer as the count. The remove method
688+
// below will take care of truncating it at the end of the
689+
// string.
690+
remove(index, (unsigned int)-1);
689691
}
690692

691693
void String::remove(unsigned int index, unsigned int count){

0 commit comments

Comments
 (0)