Improve UriComponents.sanitizeSource()

This commit is contained in:
Сергей Цыпанов 2020-07-17 12:15:48 +03:00 committed by Juergen Hoeller
parent 7b6e1c957f
commit c2122551c8
1 changed files with 4 additions and 3 deletions

View File

@ -276,7 +276,8 @@ public abstract class UriComponents implements Serializable {
*/
private static String sanitizeSource(String source) {
int level = 0;
StringBuilder sb = new StringBuilder();
int lastCharIndex = 0;
char[] chars = new char[source.length()];
for (char c : source.toCharArray()) {
if (c == '{') {
level++;
@ -287,9 +288,9 @@ public abstract class UriComponents implements Serializable {
if (level > 1 || (level == 1 && c == '}')) {
continue;
}
sb.append(c);
chars[lastCharIndex++] = c;
}
return sb.toString();
return new String(chars, 0, lastCharIndex);
}
private static String getVariableName(String match) {