[ES|QL] Retrieve token text only when necessary (#126578)

* retrieve token text only when necessary
This commit is contained in:
Fang Xing 2025-04-11 09:40:20 -04:00 committed by GitHub
parent 4cc21b6f35
commit e8ffb38d5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -0,0 +1,5 @@
pr: 126578
summary: Retrieve token text only when necessary
area: ES|QL
type: bug
issues: []

View File

@ -144,10 +144,10 @@ public final class ParserUtils {
*/
public static String nameOrPosition(Token token) {
int tokenType = token.getType();
String s = token.getText();
// Retrieve text from the token only when necessary, when the token type is known.
return switch (tokenType) {
case EsqlBaseLexer.NAMED_OR_POSITIONAL_PARAM -> s.substring(SINGLE_PARAM);
case EsqlBaseLexer.NAMED_OR_POSITIONAL_DOUBLE_PARAMS -> s.substring(DOUBLE_PARAM);
case EsqlBaseLexer.NAMED_OR_POSITIONAL_PARAM -> token.getText().substring(SINGLE_PARAM);
case EsqlBaseLexer.NAMED_OR_POSITIONAL_DOUBLE_PARAMS -> token.getText().substring(DOUBLE_PARAM);
default -> EMPTY;
};
}