Skip to content

Commit d192157

Browse files
committed
perf: precompile the whitespace pattern of LikeExpression.KeyWord.from
`KeyWord.from` runs for every `LIKE`-family condition the parser builds, and `String.replaceAll` compiled its `\s+` pattern on each call. Parsing `performance.sql` allocated 201 KB per parse for those compilations. The pattern is now a precompiled constant.
1 parent 270d861 commit d192157

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package net.sf.jsqlparser.expression.operators.relational;
1111

1212
import java.util.Locale;
13+
import java.util.regex.Pattern;
1314
import net.sf.jsqlparser.expression.BinaryExpression;
1415
import net.sf.jsqlparser.expression.Expression;
1516
import net.sf.jsqlparser.expression.ExpressionVisitor;
@@ -174,9 +175,11 @@ public LikeExpression withRightExpression(Expression arg0) {
174175
public enum KeyWord {
175176
LIKE, ILIKE, RLIKE, REGEXP_LIKE, REGEXP, GLOB, SIMILAR_TO, MATCH_ANY, MATCH_ALL, MATCH_PHRASE, MATCH_PHRASE_PREFIX, MATCH_REGEXP;
176177

178+
private static final Pattern WHITESPACE = Pattern.compile("\\s+");
179+
177180
public static KeyWord from(String keyword) {
178181
return Enum.valueOf(KeyWord.class,
179-
keyword.toUpperCase(Locale.ROOT).replaceAll("\\s+", "_"));
182+
WHITESPACE.matcher(keyword.toUpperCase(Locale.ROOT)).replaceAll("_"));
180183
}
181184
}
182185

0 commit comments

Comments
 (0)