Skip to content

Commit

Permalink
Micro-optimisation on array access
Browse files Browse the repository at this point in the history
Reduces accessing two dimensions array eight times to once.
  • Loading branch information
ravage84 committed May 2, 2024
1 parent 24fa232 commit ace61b8
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions CakePHP/Sniffs/Formatting/BlankLineBeforeReturnSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,18 @@ public function process(File $phpcsFile, $stackPtr)
$prevLineTokens = [];

while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
$currentTokenCode = $tokens[$current]['code'];
if (
$tokens[$current]['line'] == $previousLine
&& $tokens[$current]['code'] !== T_WHITESPACE
&& $tokens[$current]['code'] !== T_COMMENT
&& $tokens[$current]['code'] !== T_DOC_COMMENT_OPEN_TAG
&& $tokens[$current]['code'] !== T_DOC_COMMENT_TAG
&& $tokens[$current]['code'] !== T_DOC_COMMENT_STRING
&& $tokens[$current]['code'] !== T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$current]['code'] !== T_DOC_COMMENT_WHITESPACE
&& $currentTokenCode !== T_WHITESPACE
&& $currentTokenCode !== T_COMMENT
&& $currentTokenCode !== T_DOC_COMMENT_OPEN_TAG
&& $currentTokenCode !== T_DOC_COMMENT_TAG
&& $currentTokenCode !== T_DOC_COMMENT_STRING
&& $currentTokenCode !== T_DOC_COMMENT_CLOSE_TAG
&& $currentTokenCode !== T_DOC_COMMENT_WHITESPACE
) {
$prevLineTokens[] = $tokens[$current]['code'];
$prevLineTokens[] = $currentTokenCode;
}
$current--;
}
Expand Down

0 comments on commit ace61b8

Please sign in to comment.