Skip to content

Commit 270d861

Browse files
committed
perf: create the deque of NOT prefixes only for a negated condition
`Condition()` created a deque for leading `NOT` and `!` prefixes on every call, though few conditions have one. An empty `ArrayDeque` allocates its 17-slot array up front, so parsing `performance.sql` allocated 585 KB per parse for deques that stayed empty. The deque is now created at the first `NOT` or `!`.
1 parent a075737 commit 270d861

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12181,14 +12181,20 @@ Expression Condition():
1218112181
Expression result;
1218212182
Expression left;
1218312183
// Leading NOT / ! prefixes, leftmost token wraps outermost (issue #1170).
12184-
final Deque<Boolean> exclamationMarks = new ArrayDeque<Boolean>();
12184+
Deque<Boolean> exclamationMarks = null;
1218512185
int oraclePrior = EqualsTo.NO_ORACLE_PRIOR;
1218612186
int oracleJoin = EqualsTo.NO_ORACLE_JOIN;
1218712187
}
1218812188
{
1218912189
(
1219012190
LOOKAHEAD({ getToken(1).kind == K_NOT || "!".equals(getToken(1).image) })
12191-
( <K_NOT> { exclamationMarks.addFirst(Boolean.FALSE); } | "!" { exclamationMarks.addFirst(Boolean.TRUE); } )
12191+
( <K_NOT> | "!" )
12192+
{
12193+
if (exclamationMarks == null) {
12194+
exclamationMarks = new ArrayDeque<Boolean>();
12195+
}
12196+
exclamationMarks.addFirst("!".equals(getToken(0).image));
12197+
}
1219212198
)*
1219312199
(
1219412200
LOOKAHEAD(<K_EXISTS> JdbcNamedParameter() ":", {
@@ -12258,7 +12264,7 @@ Expression Condition():
1225812264
&& result instanceof SupportsOldOracleJoinSyntax) {
1225912265
((SupportsOldOracleJoinSyntax) result).setOraclePriorPosition(oraclePrior);
1226012266
}
12261-
while (!exclamationMarks.isEmpty()) {
12267+
while (exclamationMarks != null && !exclamationMarks.isEmpty()) {
1226212268
result = new NotExpression(result, exclamationMarks.pollFirst());
1226312269
}
1226412270
return result;

0 commit comments

Comments
 (0)