Skip to content

Commit 87fa2c3

Browse files
authored
Avoid unnecessary String instantiation in StringUtils.deleteAny()
This commit avoids unnecessary String instantiation in StringUtils.deleteAny() if nothing was deleted from the input string. Closes gh-24924
1 parent 87f28ce commit 87fa2c3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ public static String deleteAny(String inString, @Nullable String charsToDelete)
461461
result[lastCharIndex++] = c;
462462
}
463463
}
464+
if (lastCharIndex == inString.length()) {
465+
return inString;
466+
}
464467
return new String(result, 0, lastCharIndex);
465468
}
466469

0 commit comments

Comments
 (0)