Polish external contribution

This commit removes the text char[] in favor of the text String
introduced through the PR.

Closes gh-30138
This commit is contained in:
Arjen Poutsma 2023-03-22 10:14:21 +01:00
parent 2bc1aa7827
commit c68e986b75
1 changed files with 7 additions and 23 deletions

View File

@ -29,9 +29,7 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext;
*/
class LiteralPathElement extends PathElement {
private final char[] text;
private final String textString;
private final String text;
private final int len;
@ -42,17 +40,7 @@ class LiteralPathElement extends PathElement {
super(pos, separator);
this.len = literalText.length;
this.caseSensitive = caseSensitive;
if (caseSensitive) {
this.text = literalText;
}
else {
// Force all the text lower case to make matching faster
this.text = new char[literalText.length];
for (int i = 0; i < this.len; i++) {
this.text[i] = Character.toLowerCase(literalText[i]);
}
}
this.textString = new String(this.text);
this.text = new String(literalText);
}
@ -73,17 +61,13 @@ class LiteralPathElement extends PathElement {
}
if (this.caseSensitive) {
// This typically uses a JVM intrinsic
if (!this.textString.equals(value)) {
if (!this.text.equals(value)) {
return false;
}
}
else {
for (int i = 0; i < this.len; i++) {
// TODO revisit performance if doing a lot of case-insensitive matching
if (Character.toLowerCase(value.charAt(i)) != this.text[i]) {
return false;
}
if (!this.text.equalsIgnoreCase(value)) {
return false;
}
}
@ -116,7 +100,7 @@ class LiteralPathElement extends PathElement {
@Override
public char[] getChars() {
return this.text;
return this.text.toCharArray();
}
@Override
@ -126,7 +110,7 @@ class LiteralPathElement extends PathElement {
@Override
public String toString() {
return "Literal(" + this.textString + ")";
return "Literal(" + this.text + ")";
}
}