Skip to content

Commit c68e986

Browse files
committed
Polish external contribution
This commit removes the text char[] in favor of the text String introduced through the PR. Closes gh-30138
1 parent 2bc1aa7 commit c68e986

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
*/
3030
class LiteralPathElement extends PathElement {
3131

32-
private final char[] text;
33-
34-
private final String textString;
32+
private final String text;
3533

3634
private final int len;
3735

@@ -42,17 +40,7 @@ public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, ch
4240
super(pos, separator);
4341
this.len = literalText.length;
4442
this.caseSensitive = caseSensitive;
45-
if (caseSensitive) {
46-
this.text = literalText;
47-
}
48-
else {
49-
// Force all the text lower case to make matching faster
50-
this.text = new char[literalText.length];
51-
for (int i = 0; i < this.len; i++) {
52-
this.text[i] = Character.toLowerCase(literalText[i]);
53-
}
54-
}
55-
this.textString = new String(this.text);
43+
this.text = new String(literalText);
5644
}
5745

5846

@@ -73,17 +61,13 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
7361
}
7462

7563
if (this.caseSensitive) {
76-
// This typically uses a JVM intrinsic
77-
if (!this.textString.equals(value)) {
64+
if (!this.text.equals(value)) {
7865
return false;
7966
}
8067
}
8168
else {
82-
for (int i = 0; i < this.len; i++) {
83-
// TODO revisit performance if doing a lot of case-insensitive matching
84-
if (Character.toLowerCase(value.charAt(i)) != this.text[i]) {
85-
return false;
86-
}
69+
if (!this.text.equalsIgnoreCase(value)) {
70+
return false;
8771
}
8872
}
8973

@@ -116,7 +100,7 @@ public int getNormalizedLength() {
116100

117101
@Override
118102
public char[] getChars() {
119-
return this.text;
103+
return this.text.toCharArray();
120104
}
121105

122106
@Override
@@ -126,7 +110,7 @@ public boolean isLiteral() {
126110

127111
@Override
128112
public String toString() {
129-
return "Literal(" + this.textString + ")";
113+
return "Literal(" + this.text + ")";
130114
}
131115

132116
}

0 commit comments

Comments
 (0)