From c68e986b75ef999e6e99ec33b903bf039b914a2e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 22 Mar 2023 10:14:21 +0100 Subject: [PATCH] Polish external contribution This commit removes the text char[] in favor of the text String introduced through the PR. Closes gh-30138 --- .../web/util/pattern/LiteralPathElement.java | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) 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 bf2aeff244..5b8837251e 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 @@ -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 + ")"; } }