Skip to content

Commit 59fd4a8

Browse files
Optimize Lexer name tokenization
1 parent 6616825 commit 59fd4a8

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
### Changed
13+
14+
- Optimize `Lexer` name tokenization https://github.com/webonyx/graphql-php/pull/1813
15+
1216
## v15.27.2
1317

1418
### Fixed

src/Language/Lexer.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,11 @@ private function unexpectedCharacterMessage(?int $code): string
269269
*/
270270
private function readName(int $line, int $col, Token $prev): Token
271271
{
272-
$value = '';
273272
$start = $this->position;
274-
[$char, $code] = $this->readChar();
275-
276-
while (
277-
$code !== null && (
278-
$code === 95 // _
279-
|| ($code >= 48 && $code <= 57) // 0-9
280-
|| ($code >= 65 && $code <= 90) // A-Z
281-
|| ($code >= 97 && $code <= 122) // a-z
282-
)
283-
) {
284-
$value .= $char;
285-
[$char, $code] = $this->moveStringCursor(1, 1)->readChar();
286-
}
273+
$body = $this->source->body;
274+
$length = strspn($body, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_', $this->byteStreamPosition);
275+
$value = substr($body, $this->byteStreamPosition, $length);
276+
$this->moveStringCursor($length, $length);
287277

288278
return new Token(
289279
Token::NAME,

0 commit comments

Comments
 (0)