Skip to content

Commit 268d029

Browse files
committed
Avoid substring allocation in StringUtils.replace
Closes gh-24023
1 parent 85471d0 commit 268d029

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
@@ -417,14 +417,14 @@ public static String replace(String inString, String oldPattern, @Nullable Strin
417417
int pos = 0; // our position in the old string
418418
int patLen = oldPattern.length();
419419
while (index >= 0) {
420-
sb.append(inString.substring(pos, index));
420+
sb.append(inString, pos, index);
421421
sb.append(newPattern);
422422
pos = index + patLen;
423423
index = inString.indexOf(oldPattern, pos);
424424
}
425425

426426
// append any characters to the right of a match
427-
sb.append(inString.substring(pos));
427+
sb.append(inString, pos, inString.length());
428428
return sb.toString();
429429
}
430430

0 commit comments

Comments
 (0)