Skip to content

Commit

Permalink
Merge pull request #84 from samsonasik/improve-performance
Browse files Browse the repository at this point in the history
Improve performance : count() and array_push removal when possible
  • Loading branch information
samsonasik committed Jun 24, 2021
2 parents cee13ca + 0878f55 commit 13af250
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ConfigPostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use function array_intersect_key;
use function array_key_exists;
use function array_pop;
use function array_push;
use function count;
use function in_array;
use function is_array;
use function is_callable;
Expand Down Expand Up @@ -70,7 +68,7 @@ function ($value) {
function ($value, array $keys) {
$key = array_pop($keys);
// Only worried about a top-level "router" key.
return $key === 'router' && count($keys) === 0 && is_array($value)
return $key === 'router' && $keys === [] && is_array($value)
? [$this, 'noopReplacement']
: null;
},
Expand All @@ -84,7 +82,7 @@ function ($value) {

// Array values
function ($value, array $keys) {
return 0 !== count($keys) && is_array($value)
return $keys !== [] && is_array($value)
? [$this, '__invoke']
: null;
},
Expand Down Expand Up @@ -153,7 +151,7 @@ private function replace($value, array $keys, $key = null)
{
// Add new key to the list of keys.
// We do not need to remove it later, as we are working on a copy of the array.
array_push($keys, $key);
$keys[] = $key;

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

0 comments on commit 13af250

Please sign in to comment.