Skip to content

Commit 8321c26

Browse files
stofkeradus
authored andcommitted
Optimize the namespaces analyzer
Instead of looping on all tokens, even inside the namespace it identified, the analyzer now continues the analysis after the end of the identified namespace, thanks to the fact that namespaces cannot be nested.
1 parent ceec561 commit 8321c26

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Tokenizer/Analyzer/NamespacesAnalyzer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function getDeclarations(Tokens $tokens)
2929
{
3030
$namespaces = [];
3131

32-
foreach ($tokens as $index => $token) {
32+
for ($index = 1, $count = \count($tokens); $index < $count; ++$index) {
33+
$token = $tokens[$index];
34+
3335
if (!$token->isGivenKind(T_NAMESPACE)) {
3436
continue;
3537
}
@@ -57,6 +59,9 @@ public function getDeclarations(Tokens $tokens)
5759
$index,
5860
$scopeEndIndex
5961
);
62+
63+
// Continue the analysis after the end of this namespace to find the next one
64+
$index = $scopeEndIndex;
6065
}
6166

6267
if (0 === count($namespaces)) {

0 commit comments

Comments
 (0)