Skip to content

Commit 2a63147

Browse files
committed
Avoid substring allocation in StringUtils.replace
Closes gh-24023
1 parent 41072e3 commit 2a63147

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

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

0 commit comments

Comments
 (0)