Skip to content

Commit

Permalink
Improve critical matching loop a little
Browse files Browse the repository at this point in the history
+7% speedup
  • Loading branch information
mvorisek committed Sep 10, 2024
1 parent 21b7e81 commit 808c095
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,14 +899,15 @@ private function makeTokenizeRegex(array $regexes): string
*/
public function tokenize(string $string): Cursor
{
$tokens = [];
$tokenizeRegex = $this->tokenizeRegex;
$upper = strtoupper($string);

$upper = strtoupper($string);
$tokens = [];
$offset = 0;

while ($offset < strlen($string)) {
// Get the next token and the token type
preg_match($this->tokenizeRegex, $upper, $matches, 0, $offset);
preg_match($tokenizeRegex, $upper, $matches, 0, $offset);
assert(($matches[0] ?? '') !== '');

while (is_int($lastMatchesKey = array_key_last($matches))) {
Expand Down

0 comments on commit 808c095

Please sign in to comment.