Skip to content

Commit 0878f55

Browse files
committed
Improve performance:
- Use empty [] comparison instead of count() for array when possible - Use array assign instead of array_push when possible Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
1 parent ff8e9a7 commit 0878f55

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
@@ -11,8 +11,6 @@
1111
use function array_intersect_key;
1212
use function array_key_exists;
1313
use function array_pop;
14-
use function array_push;
15-
use function count;
1614
use function in_array;
1715
use function is_array;
1816
use function is_callable;
@@ -76,7 +74,7 @@ function ($value) {
7674
function ($value, array $keys) {
7775
$key = array_pop($keys);
7876
// Only worried about a top-level "router" key.
79-
return $key === 'router' && count($keys) === 0 && is_array($value)
77+
return $key === 'router' && $keys === [] && is_array($value)
8078
? [$this, 'noopReplacement']
8179
: null;
8280
},
@@ -90,7 +88,7 @@ function ($value) {
9088

9189
// Array values
9290
function ($value, array $keys) {
93-
return 0 !== count($keys) && is_array($value)
91+
return $keys !== [] && is_array($value)
9492
? [$this, '__invoke']
9593
: null;
9694
},
@@ -159,7 +157,7 @@ private function replace($value, array $keys, $key = null)
159157
{
160158
// Add new key to the list of keys.
161159
// We do not need to remove it later, as we are working on a copy of the array.
162-
array_push($keys, $key);
160+
$keys[] = $key;
163161

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

0 commit comments

Comments
 (0)