Skip to content

Commit 824f362

Browse files
committed
Merge branch 'perf-micro-opt-eat'
2 parents 696acc3 + 3f08e42 commit 824f362

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Parser.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,26 @@ private function eat1($kind) {
396396
return new MissingToken($kind, $token->fullStart);
397397
}
398398

399+
/**
400+
* Retrieve the current token, and check that it's of the kind $kind.
401+
* If so, advance and return the token. Otherwise return a MissingToken for
402+
* the expected token.
403+
*
404+
* This is faster than calling eat() if there is a single token.
405+
*
406+
* @param int $kind
407+
* @return Token
408+
*/
409+
private function eat1($kind) {
410+
$token = $this->token;
411+
if ($token->kind === $kind) {
412+
$this->token = $this->lexer->scanNextToken();
413+
return $token;
414+
}
415+
// TODO include optional grouping for token kinds
416+
return new MissingToken($kind, $token->fullStart);
417+
}
418+
399419
/**
400420
* @param int|int[] ...$kinds (Can provide a single value with a list of kinds, or multiple kinds)
401421
* @return Token|null

0 commit comments

Comments
 (0)