Generic/ByteOrderMark: small performance improvement #360
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 BOM character must be the first character of the file. This means that this sniff only needs to check the file once, but its code was executed for each occurrence of the T_INLINE_HTML token.
As discussed in #278 (comment), this PR changes the sniff code to return the number of tokens in all of its exit points to ensure that PHPCS executes it just a single time per file.
I noticed that some sniffs return
$phpcsFile->numTokens
while others return($phpcsFile->numTokens + 1)
to ignore the rest of the file. As far as I could check, returning the number of tokens is enough as the code checks if the returned value is greater than the current position in the token array, so I went with this option. It is not clear to me why some sniffs return the number of tokens plus one. Highlighting this in case I'm missing something, and the code in this PR should return($phpcsFile->numTokens + 1)
.Suggested changelog entry
Small performance improvement for the Generic.Files.ByteOrderMark sniff
Related issues/external references
Discussed in #278 (comment)
Types of changes
PR checklist