From 808c095dc9a6d3ec9ba24761603ed3b17dec6e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 10 Sep 2024 17:58:05 +0200 Subject: [PATCH] Improve critical matching loop a little +7% speedup --- src/Tokenizer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Tokenizer.php b/src/Tokenizer.php index ac9836d..b163804 100644 --- a/src/Tokenizer.php +++ b/src/Tokenizer.php @@ -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))) {