New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NamespacesAnalyzer - Optimize performance #3877
Conversation
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.
d75a514
to
8321c26
Compare
We do push code refactoring to oldest maintained branch, I have changed the target and recreated your branch @stof (force-push) |
Thank you @stof. |
This PR was merged into the 2.12 branch. Discussion ---------- NamespacesAnalyzer - Optimize performance 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. When implementing #3876, I compared the NamespacesAnalyzer implementation with `\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::getUserDefinedNamespaces`. The NamespacesAnalyzer also identifies the namespace name instead of skipping over it (and returns the global namespace too). But I found out that NativeFunctionInvocationFixer was more optimized, as it was not re-analyzing all tokens inside a namespace. This makes NamespacesAnalyzer implement the same optimization. Commits ------- 8321c26 Optimize the namespaces analyzer
…r to remove duplicated code (stof) This PR was merged into the 2.12 branch. Discussion ---------- NativeFunctionInvocationFixer - use the NamespacesAnalyzer to remove duplicated code Instead of maintaining 2 different analyzers to find the beginning and the end of a namespace block, this reuses the existing NamespacesAnalyzer. See #3877 which optimizes it based on existing optimization in the implementation I'm deleting here. Commits ------- b16c2f0 Use the NamespacesAnalyzer in the NativeFunctionInvocationFixer
I was not aware of that. Good to know. |
for next MINOR branch we do push only what MINOR is reserved for - features ;) the more similar codebase between versions, the easier to maintain |
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.
When implementing #3876, I compared the NamespacesAnalyzer implementation with
\PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer::getUserDefinedNamespaces
. The NamespacesAnalyzer also identifies the namespace name instead of skipping over it (and returns the global namespace too). But I found out that NativeFunctionInvocationFixer was more optimized, as it was not re-analyzing all tokens inside a namespace. This makes NamespacesAnalyzer implement the same optimization.