diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java index 5a2de132b4f8..bf2aeff244fe 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java @@ -31,6 +31,8 @@ class LiteralPathElement extends PathElement { private final char[] text; + private final String textString; + private final int len; private final boolean caseSensitive; @@ -50,6 +52,7 @@ public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, ch this.text[i] = Character.toLowerCase(literalText[i]); } } + this.textString = new String(this.text); } @@ -70,10 +73,9 @@ public boolean matches(int pathIndex, MatchingContext matchingContext) { } if (this.caseSensitive) { - for (int i = 0; i < this.len; i++) { - if (value.charAt(i) != this.text[i]) { - return false; - } + // This typically uses a JVM intrinsic + if (!this.textString.equals(value)) { + return false; } } else { @@ -124,7 +126,7 @@ public boolean isLiteral() { @Override public String toString() { - return "Literal(" + String.valueOf(this.text) + ")"; + return "Literal(" + this.textString + ")"; } }