Skip to content

Commit e8ffb38

Browse files
[ES|QL] Retrieve token text only when necessary (#126578)
* retrieve token text only when necessary
1 parent 4cc21b6 commit e8ffb38

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/changelog/126578.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126578
2+
summary: Retrieve token text only when necessary
3+
area: ES|QL
4+
type: bug
5+
issues: []

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ParserUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ public static String text(ParseTree node) {
144144
*/
145145
public static String nameOrPosition(Token token) {
146146
int tokenType = token.getType();
147-
String s = token.getText();
147+
// Retrieve text from the token only when necessary, when the token type is known.
148148
return switch (tokenType) {
149-
case EsqlBaseLexer.NAMED_OR_POSITIONAL_PARAM -> s.substring(SINGLE_PARAM);
150-
case EsqlBaseLexer.NAMED_OR_POSITIONAL_DOUBLE_PARAMS -> s.substring(DOUBLE_PARAM);
149+
case EsqlBaseLexer.NAMED_OR_POSITIONAL_PARAM -> token.getText().substring(SINGLE_PARAM);
150+
case EsqlBaseLexer.NAMED_OR_POSITIONAL_DOUBLE_PARAMS -> token.getText().substring(DOUBLE_PARAM);
151151
default -> EMPTY;
152152
};
153153
}

0 commit comments

Comments
 (0)