[Rules] balanceParentheses(): Always use String.reserve when changing string

This commit is contained in:
Ton Huisman
2021-03-27 16:30:18 +01:00
parent 098bf4dbba
commit 2f5ede7795
+3 -1
View File
@@ -1323,12 +1323,14 @@ int balanceParentheses(String& string) {
break;
}
}
if (left != right) {
string.reserve(string.length() + abs(right - left)); // Re-allocate max. once
}
if (left > right) {
for (int i = 0; i < left - right; i++) {
string += ')';
}
} else if (right > left) {
string.reserve(string.length() + (right - left)); // Re-allocate max. once
for (int i = 0; i < right - left; i++) {
string = String(F("(")) + string; // This is quite 'expensive'
}