Skip to content

Commit ae70bf7

Browse files
committed
Merge pull request #30138 from yuzawa-san:LiteralPathElement-string-equals
* gh-30138: Polish external contribution Use String.equals() in LiteralPathElement
2 parents 570d21e + c68e986 commit ae70bf7

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

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

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

32-
private final char[] text;
32+
private final String text;
3333

3434
private final int len;
3535

@@ -40,16 +40,7 @@ public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, ch
4040
super(pos, separator);
4141
this.len = literalText.length;
4242
this.caseSensitive = caseSensitive;
43-
if (caseSensitive) {
44-
this.text = literalText;
45-
}
46-
else {
47-
// Force all the text lower case to make matching faster
48-
this.text = new char[literalText.length];
49-
for (int i = 0; i < this.len; i++) {
50-
this.text[i] = Character.toLowerCase(literalText[i]);
51-
}
52-
}
43+
this.text = new String(literalText);
5344
}
5445

5546

@@ -70,18 +61,13 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) {
7061
}
7162

7263
if (this.caseSensitive) {
73-
for (int i = 0; i < this.len; i++) {
74-
if (value.charAt(i) != this.text[i]) {
75-
return false;
76-
}
64+
if (!this.text.equals(value)) {
65+
return false;
7766
}
7867
}
7968
else {
80-
for (int i = 0; i < this.len; i++) {
81-
// TODO revisit performance if doing a lot of case-insensitive matching
82-
if (Character.toLowerCase(value.charAt(i)) != this.text[i]) {
83-
return false;
84-
}
69+
if (!this.text.equalsIgnoreCase(value)) {
70+
return false;
8571
}
8672
}
8773

@@ -114,7 +100,7 @@ public int getNormalizedLength() {
114100

115101
@Override
116102
public char[] getChars() {
117-
return this.text;
103+
return this.text.toCharArray();
118104
}
119105

120106
@Override
@@ -124,7 +110,7 @@ public boolean isLiteral() {
124110

125111
@Override
126112
public String toString() {
127-
return "Literal(" + String.valueOf(this.text) + ")";
113+
return "Literal(" + this.text + ")";
128114
}
129115

130116
}

0 commit comments

Comments
 (0)