Skip to content

Commit e48a222

Browse files
committed
Generic/ScopeIndent: lower memory usage
Based on an analysis of some runs with [BlackFire](https://blackfire.io/), this small tweak will lower the memory usage of any run which includes the `Generic.WhiteSpace.ScopeIndent` - and by extension, the `PEAR.WhiteSpace.ScopeIndent` - sniff significantly. A comparison between a run on `master` and a run on this branch can be found here: https://blackfire.io/profiles/compare/7adc96c7-09a4-4ec8-8821-bbf9d5906b2f/graph **Note**: this comparison is only available for 24 hours. The benchmark was created by running PHPCS over itself with the native ruleset and this command: `phpcs -p --report-source --no-cache`.
1 parent b53f64e commit e48a222

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ public function process(File $phpcsFile, $stackPtr)
238238
if (isset($tokens[$parenCloser]['nested_parenthesis']) === true
239239
&& empty($tokens[$parenCloser]['nested_parenthesis']) === false
240240
) {
241-
end($tokens[$parenCloser]['nested_parenthesis']);
242-
$parens = key($tokens[$parenCloser]['nested_parenthesis']);
241+
$parens = $tokens[$parenCloser]['nested_parenthesis'];
242+
end($parens);
243+
$parens = key($parens);
243244
if ($this->debug === true) {
244245
$line = $tokens[$parens]['line'];
245246
echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
@@ -250,8 +251,9 @@ public function process(File $phpcsFile, $stackPtr)
250251
if (isset($tokens[$parenCloser]['conditions']) === true
251252
&& empty($tokens[$parenCloser]['conditions']) === false
252253
) {
253-
end($tokens[$parenCloser]['conditions']);
254-
$condition = key($tokens[$parenCloser]['conditions']);
254+
$condition = $tokens[$parenCloser]['conditions'];
255+
end($condition);
256+
$condition = key($condition);
255257
if ($this->debug === true) {
256258
$line = $tokens[$condition]['line'];
257259
$type = $tokens[$condition]['type'];
@@ -511,8 +513,9 @@ public function process(File $phpcsFile, $stackPtr)
511513
&& $tokens[$checkToken]['scope_opener'] === $checkToken))
512514
) {
513515
if (empty($tokens[$checkToken]['conditions']) === false) {
514-
end($tokens[$checkToken]['conditions']);
515-
$condition = key($tokens[$checkToken]['conditions']);
516+
$condition = $tokens[$checkToken]['conditions'];
517+
end($condition);
518+
$condition = key($condition);
516519
} else {
517520
$condition = $tokens[$checkToken]['scope_condition'];
518521
}
@@ -653,8 +656,9 @@ public function process(File $phpcsFile, $stackPtr)
653656
if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true
654657
&& empty($tokens[$scopeCloser]['nested_parenthesis']) === false
655658
) {
656-
end($tokens[$scopeCloser]['nested_parenthesis']);
657-
$parens = key($tokens[$scopeCloser]['nested_parenthesis']);
659+
$parens = $tokens[$scopeCloser]['nested_parenthesis'];
660+
end($parens);
661+
$parens = key($parens);
658662
if ($this->debug === true) {
659663
$line = $tokens[$parens]['line'];
660664
echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
@@ -665,8 +669,9 @@ public function process(File $phpcsFile, $stackPtr)
665669
if (isset($tokens[$scopeCloser]['conditions']) === true
666670
&& empty($tokens[$scopeCloser]['conditions']) === false
667671
) {
668-
end($tokens[$scopeCloser]['conditions']);
669-
$condition = key($tokens[$scopeCloser]['conditions']);
672+
$condition = $tokens[$scopeCloser]['conditions'];
673+
end($condition);
674+
$condition = key($condition);
670675
if ($this->debug === true) {
671676
$line = $tokens[$condition]['line'];
672677
$type = $tokens[$condition]['type'];
@@ -1181,8 +1186,9 @@ public function process(File $phpcsFile, $stackPtr)
11811186
if (isset($tokens[$i]['nested_parenthesis']) === true
11821187
&& empty($tokens[$i]['nested_parenthesis']) === false
11831188
) {
1184-
end($tokens[$i]['nested_parenthesis']);
1185-
$parens = key($tokens[$i]['nested_parenthesis']);
1189+
$parens = $tokens[$i]['nested_parenthesis'];
1190+
end($parens);
1191+
$parens = key($parens);
11861192
if ($this->debug === true) {
11871193
$line = $tokens[$parens]['line'];
11881194
echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
@@ -1193,8 +1199,9 @@ public function process(File $phpcsFile, $stackPtr)
11931199
if (isset($tokens[$i]['conditions']) === true
11941200
&& empty($tokens[$i]['conditions']) === false
11951201
) {
1196-
end($tokens[$i]['conditions']);
1197-
$condition = key($tokens[$i]['conditions']);
1202+
$condition = $tokens[$i]['conditions'];
1203+
end($condition);
1204+
$condition = key($condition);
11981205
if ($this->debug === true) {
11991206
$line = $tokens[$condition]['line'];
12001207
$type = $tokens[$condition]['type'];

0 commit comments

Comments
 (0)