Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5aaeb83

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Optimize Lexer::tokenize()
1 parent 07c49b0 commit 5aaeb83

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

‎src/Lexer/Lexer.php‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,11 @@ public function tokenize(string $s): array
105105
assert($this->regexp !== null);
106106
assert($this->types !== null);
107107

108-
preg_match_all($this->regexp, $s, $tokens, PREG_SET_ORDER);
109-
110-
$count = count($this->types);
111-
foreach ($tokens as &$match) {
112-
for ($i = 1; $i <= $count; $i++) {
113-
if ($match[$i] !== null && $match[$i] !== '') {
114-
$match = [$match[0], $this->types[$i - 1]];
115-
break;
116-
}
117-
}
108+
preg_match_all($this->regexp, $s, $matches, PREG_SET_ORDER);
109+
110+
$tokens = [];
111+
foreach ($matches as $match) {
112+
$tokens[] = [$match[0], $this->types[count($match) - 2]];
118113
}
119114

120115
$tokens[] = ['', self::TOKEN_END];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /