Skip to content

Commit 13af250

Browse files
authored
Merge pull request #84 from samsonasik/improve-performance
Improve performance : count() and array_push removal when possible
2 parents cee13ca + 0878f55 commit 13af250

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/ConfigPostProcessor.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use function array_intersect_key;
66
use function array_key_exists;
77
use function array_pop;
8-
use function array_push;
9-
use function count;
108
use function in_array;
119
use function is_array;
1210
use function is_callable;
@@ -70,7 +68,7 @@ function ($value) {
7068
function ($value, array $keys) {
7169
$key = array_pop($keys);
7270
// Only worried about a top-level "router" key.
73-
return $key === 'router' && count($keys) === 0 && is_array($value)
71+
return $key === 'router' && $keys === [] && is_array($value)
7472
? [$this, 'noopReplacement']
7573
: null;
7674
},
@@ -84,7 +82,7 @@ function ($value) {
8482

8583
// Array values
8684
function ($value, array $keys) {
87-
return 0 !== count($keys) && is_array($value)
85+
return $keys !== [] && is_array($value)
8886
? [$this, '__invoke']
8987
: null;
9088
},
@@ -153,7 +151,7 @@ private function replace($value, array $keys, $key = null)
153151
{
154152
// Add new key to the list of keys.
155153
// We do not need to remove it later, as we are working on a copy of the array.
156-
array_push($keys, $key);
154+
$keys[] = $key;
157155

158156
// Identify rewrite strategy and perform replacements
159157
$rewriteRule = $this->replacementRuleMatch($value, $keys);

0 commit comments

Comments
 (0)