4.0 | Variable sniffs: minor performance tweak#374
Merged
Conversation
8e5fb89 to
580a850
Compare
Member
Author
|
Rebased without changes. Merging once the build passes. |
Member
Author
|
On second thought, I will delay merging this PR until the 3.10.0 release as there is a, albeit small, chance that this change could break external sniffs which extend one of the sniffs involved in this PR (as they would inherit the change, which may not be the desired behaviour for their sniff). |
580a850 to
d42dedd
Compare
d42dedd to
70e1b54
Compare
The `AbstractVariableSniff` by default listens to all `T_VARIABLE`, `T_DOUBLE_QUOTED_STRING` and `T_HEREDOC` tokens. The majority of the sniffs extending the `AbstractVariableSniff`, however, only handle `T_VARIABLE` tokens and in particular, only handle `T_VARIABLE` tokens when in an OO scope and nothing more. This small tweak means these sniffs will no longer "listen" to `T_DOUBLE_QUOTED_STRING` and `T_HEREDOC` tokens, which should make them marginally faster, in particular for code bases containing lots of `T_DOUBLE_QUOTED_STRING` and `T_HEREDOC` tokens. It also means that these sniff will no longer be triggered for `T_VARIABLE` tokens outside of an OO context.
70e1b54 to
c403015
Compare
petitphp
approved these changes
Apr 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
AbstractVariableSniffby default listens to allT_VARIABLE,T_DOUBLE_QUOTED_STRINGandT_HEREDOCtokens.The majority of the sniffs extending the
AbstractVariableSniff, however, only handleT_VARIABLEtokens and in particular, only handleT_VARIABLEtokens when in an OO scope and nothing more.This small tweak means these sniffs will no longer "listen" to
T_DOUBLE_QUOTED_STRINGandT_HEREDOCtokens, which should make them marginally faster, in particular for code bases containing lots ofT_DOUBLE_QUOTED_STRINGandT_HEREDOCtokens.It also means that these sniff will no longer be triggered for
T_VARIABLEtokens outside of an OO context.Suggested changelog entry
Changed:
External sniffs which extend one of these sniffs may need adjustment if they want to retain the old behaviour.