Skip to content

Commit d896a6a

Browse files
committed
perf: match XML function names without joining the name parts
`consumeXmlLeadingKeyword` and `FunctionArgumentList` called `Function.getName()` for every function to check for `XMLPARSE`, `XMLELEMENT` or `XMLFOREST`, and `getName()` joins the name parts into a new string on each call. Both checks now compare the single name part.
1 parent a6624b7 commit d896a6a

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,8 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
13331333
* everywhere else, e.g. f(content).
13341334
*/
13351335
private void consumeXmlLeadingKeyword(Function function) {
1336-
String name = function.getName();
1337-
if (name == null) {
1338-
return;
1339-
}
1340-
name = name.toUpperCase(java.util.Locale.ROOT);
1341-
if (!"XMLPARSE".equals(name) && !"XMLELEMENT".equals(name) && !"XMLFOREST".equals(name)) {
1336+
if (!hasUnqualifiedName(function, "XMLPARSE") && !hasUnqualifiedName(function, "XMLELEMENT")
1337+
&& !hasUnqualifiedName(function, "XMLFOREST")) {
13421338
return;
13431339
}
13441340
Token token = getToken(1);
@@ -1358,6 +1354,12 @@ public class CCJSqlParser extends AbstractJSqlParser<CCJSqlParser> {
13581354
function.setExtraKeyword(getNextToken().image);
13591355
}
13601356

1357+
// Matches the single name part, since getName() joins the parts into a new string on each call.
1358+
private static boolean hasUnqualifiedName(Function function, String name) {
1359+
List<String> nameParts = function.getMultipartName();
1360+
return nameParts != null && nameParts.size() == 1 && name.equalsIgnoreCase(nameParts.get(0));
1361+
}
1362+
13611363
/**
13621364
* An unquoted YEAR, MONTH, DAY, HOUR, MINUTE or SECOND passed on its own as a function argument, as in
13631365
* DATEADD(day, 1, d), is a date unit. Anywhere else it is an ordinary identifier, so it is parsed as a
@@ -15439,7 +15441,7 @@ ExpressionList FunctionArgumentList(Function retval):
1543915441
Token extraKeywordToken;
1544015442
}
1544115443
{
15442-
{ if ("XMLFOREST".equalsIgnoreCase(retval.getName())) { return XmlForestArguments(); } }
15444+
{ if (hasUnqualifiedName(retval, "XMLFOREST")) { return XmlForestArguments(); } }
1544315445
[ LOOKAHEAD(2) extraKeywordToken = <K_TABLE> { retval.setExtraKeyword(extraKeywordToken.image); } ]
1544415446
expressionList=ExpressionList()
1544515447
// explicit lookahead: InternalFunction accepts ORDER BY after IGNORE NULLS too

0 commit comments

Comments
 (0)