From 0878f55130e5d35d2503e5058fae1b2f8ef8db96 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 3 Jun 2021 13:44:57 +0700 Subject: [PATCH] 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 --- src/ConfigPostProcessor.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ConfigPostProcessor.php b/src/ConfigPostProcessor.php index bac7b97..0c35024 100644 --- a/src/ConfigPostProcessor.php +++ b/src/ConfigPostProcessor.php @@ -11,8 +11,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; @@ -76,7 +74,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; }, @@ -90,7 +88,7 @@ function ($value) { // Array values function ($value, array $keys) { - return 0 !== count($keys) && is_array($value) + return $keys !== [] && is_array($value) ? [$this, '__invoke'] : null; }, @@ -159,7 +157,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);