Avoid substring allocation in StringUtils.replace
Closes gh-24023
This commit is contained in:
parent
b4e1d48322
commit
4af6039359
|
@ -420,14 +420,14 @@ public abstract class StringUtils {
|
||||||
int pos = 0; // our position in the old string
|
int pos = 0; // our position in the old string
|
||||||
int patLen = oldPattern.length();
|
int patLen = oldPattern.length();
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
sb.append(inString.substring(pos, index));
|
sb.append(inString, pos, index);
|
||||||
sb.append(newPattern);
|
sb.append(newPattern);
|
||||||
pos = index + patLen;
|
pos = index + patLen;
|
||||||
index = inString.indexOf(oldPattern, pos);
|
index = inString.indexOf(oldPattern, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// append any characters to the right of a match
|
// append any characters to the right of a match
|
||||||
sb.append(inString.substring(pos));
|
sb.append(inString, pos, inString.length());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue