Skip to content

Commit ee2fe1d

Browse files
committed
Avoid substring allocation in StringUtils.replace
Closes gh-24023
1 parent f190168 commit ee2fe1d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ public static String replace(String inString, String oldPattern, String newPatte
399399
int pos = 0; // our position in the old string
400400
int patLen = oldPattern.length();
401401
while (index >= 0) {
402-
sb.append(inString.substring(pos, index));
402+
sb.append(inString, pos, index);
403403
sb.append(newPattern);
404404
pos = index + patLen;
405405
index = inString.indexOf(oldPattern, pos);
406406
}
407407

408408
// append any characters to the right of a match
409-
sb.append(inString.substring(pos));
409+
sb.append(inString, pos, inString.length());
410410
return sb.toString();
411411
}
412412

0 commit comments

Comments
 (0)