From 15a2398f7f328533640de33275ab8779f6cddd32 Mon Sep 17 00:00:00 2001 From: iifawzi Date: Wed, 7 Dec 2022 20:23:37 +0200 Subject: [PATCH 1/2] Increasing the idx of the tokens instead of using getNext to skip current token Signed-off-by: iifawzi --- src/Components/AlterOperation.php | 14 ++------------ src/Statements/ExplainStatement.php | 6 +++--- src/Statements/WithStatement.php | 6 +----- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index 22bd9b9cb..8408bf16b 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -349,12 +349,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = } } elseif (! self::checkIfTokenQuotedSymbol($token)) { if (! empty(Parser::$STATEMENT_PARSERS[$token->value])) { - // We want to get the next non-comment and non-space token after $token - // therefore, the first getNext call will start with the current $idx which's $token, - // will return it and increase $idx by 1, which's not guaranteed to be non-comment - // and non-space, that's why we're calling getNext again. - - $list->getNext(); + $list->idx++; // Ignore the current token $nextToken = $list->getNext(); if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') { @@ -387,12 +382,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = $ret->unknown[] = $token; } elseif ($state === 3) { if ($partitionState === 0) { - // We want to get the next non-comment and non-space token after $token - // therefore, the first getNext call will start with the current $idx which's $token, - // will return it and increase $idx by 1, which's not guaranteed to be non-comment - // and non-space, that's why we're calling getNext again. - - $list->getNext(); + $list->idx++; // Ignore the current token $nextToken = $list->getNext(); if ( ($token->type === Token::TYPE_KEYWORD) diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php index 1bdb70007..5ce86baed 100644 --- a/src/Statements/ExplainStatement.php +++ b/src/Statements/ExplainStatement.php @@ -134,13 +134,13 @@ public function parse(Parser $parser, TokensList $list) $state = 2; } elseif ($state === 2) { $currIdx = $list->idx; - $currToken = $list->getNext(); + $list->idx++; // Ignore the current token $nextToken = $list->getNext(); $list->idx = $currIdx; if ($token->keyword === 'FOR' && $nextToken->keyword === 'CONNECTION') { - $forToken = $list->getNext(); // FOR - $connectionToken = $list->getNext(); // CONNECTION + $list->idx++; // Ignore the current token + $list->getNext(); // CONNECTION $nextToken = $list->getNext(); // Identifier $this->connectionId = $nextToken->value; break; diff --git a/src/Statements/WithStatement.php b/src/Statements/WithStatement.php index cd90aebf4..eb207496f 100644 --- a/src/Statements/WithStatement.php +++ b/src/Statements/WithStatement.php @@ -142,11 +142,7 @@ public function parse(Parser $parser, TokensList $list) } elseif ($state === 3) { $idxBeforeGetNext = $list->idx; - // We want to get the next non-comment and non-space token after $token - // therefore, the first getNext call will start with the current $idx which's $token, - // will return it and increase $idx by 1, which's not guaranteed to be non-comment - // and non-space, that's why we're calling getNext again. - $list->getNext(); + $list->idx++; // Ignore the current token $nextKeyword = $list->getNext(); if (! ($token->value === '(' && ($nextKeyword && $nextKeyword->value === 'SELECT'))) { From 3ed503fabc671f1a46cb0350ee96d9b172ac2d3d Mon Sep 17 00:00:00 2001 From: iifawzi Date: Wed, 7 Dec 2022 20:44:02 +0200 Subject: [PATCH 2/2] Add to changelog Signed-off-by: iifawzi --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 925e7c2bf..3099a5fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fixed differentiating between `ANALYZE` and `EXPLAIN` statements (#386) * Added "NOT" to the select options (#374) * Implement the `EXPLAIN` Parser (#389) +* Performance improvement to use less the `nextToken()` function (#397) ## [5.5.0] - 2021-12-08