Browse Source

Merge pull request #30138 from yuzawa-san:LiteralPathElement-string-equals

* gh-30138:
  Polish external contribution
  Use String.equals() in LiteralPathElement
pull/30169/head
Arjen Poutsma 2 years ago
parent
commit
ae70bf7c38
  1. 30
      spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java

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

@ -29,7 +29,7 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext; @@ -29,7 +29,7 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext;
*/
class LiteralPathElement extends PathElement {
private final char[] text;
private final String text;
private final int len;
@ -40,16 +40,7 @@ class LiteralPathElement extends PathElement { @@ -40,16 +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.text = new String(literalText);
}
@ -70,18 +61,13 @@ class LiteralPathElement extends PathElement { @@ -70,18 +61,13 @@ class LiteralPathElement extends PathElement {
}
if (this.caseSensitive) {
for (int i = 0; i < this.len; i++) {
if (value.charAt(i) != this.text[i]) {
return false;
}
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;
}
}
@ -114,7 +100,7 @@ class LiteralPathElement extends PathElement { @@ -114,7 +100,7 @@ class LiteralPathElement extends PathElement {
@Override
public char[] getChars() {
return this.text;
return this.text.toCharArray();
}
@Override
@ -124,7 +110,7 @@ class LiteralPathElement extends PathElement { @@ -124,7 +110,7 @@ class LiteralPathElement extends PathElement {
@Override
public String toString() {
return "Literal(" + String.valueOf(this.text) + ")";
return "Literal(" + this.text + ")";
}
}

Loading…
Cancel
Save