From 94314f9d5510f1a74d61f8ec2e1c698a3419e8cd Mon Sep 17 00:00:00 2001 From: Iltar van der Berg Date: Wed, 2 May 2018 12:14:26 +0200 Subject: [PATCH] [DI] Minor performance tweak in PriorityTaggedServiceTrait --- link | 2 +- .../Bridge/Monolog/Processor/DebugProcessor.php | 6 +++++- .../Tests/Processor/DebugProcessorTest.php | 8 ++++++++ .../Console/Descriptor/TextDescriptor.php | 4 ++-- .../DependencyInjection/Compiler/PassConfig.php | 4 ++-- .../Compiler/PriorityTaggedServiceTrait.php | 2 +- .../Tests/Compiler/PassConfigTest.php | 16 ++++++++++++++++ .../Compiler/PriorityTaggedServiceTraitTest.php | 7 +++++++ .../Tests/Fixtures/includes/ProjectExtension.php | 3 +-- .../DependencyInjection/MessengerPass.php | 2 +- 10 files changed, 44 insertions(+), 10 deletions(-) diff --git a/link b/link index 6a2ec15e2210..22d076c9f13f 100755 --- a/link +++ b/link @@ -38,7 +38,7 @@ $sfPackages = array('symfony/symfony' => __DIR__); $filesystem = new Filesystem(); $braces = array('Bundle', 'Bridge', 'Component', 'Component/Security'); -$directories = call_user_func_array('array_merge', array_values(array_map(function ($part) { +$directories = array_merge(...array_values(array_map(function ($part) { return glob(__DIR__.'/src/Symfony/'.$part.'/*', GLOB_ONLYDIR | GLOB_NOSORT); }, $braces))); diff --git a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php index 7346d4ee946e..a6998517e700 100644 --- a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php @@ -64,7 +64,11 @@ public function getLogs(/* Request $request = null */) return $this->records[$hash]; } - return $this->records ? \call_user_func_array('array_merge', $this->records) : array(); + if (0 === \count($this->records)) { + return array(); + } + + return array_merge(...array_values($this->records)); } /** diff --git a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php index e85ded5b484b..9acaf6074ec8 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php @@ -29,6 +29,14 @@ public function testDebugProcessor() $this->assertSame(1, $processor->countErrors()); } + public function testDebugProcessorWithoutLogs() + { + $processor = new DebugProcessor(); + + $this->assertCount(0, $processor->getLogs()); + $this->assertSame(0, $processor->countErrors()); + } + public function testWithRequestStack() { $stack = new RequestStack(); diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index 527afb12f0ac..e44cd55b8bac 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -210,9 +210,9 @@ protected function describeApplication(Application $application, array $options } // calculate max. width based on available commands per namespace - $width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) { + $width = $this->getColumnWidth(array_merge(...array_values(array_map(function ($namespace) use ($commands) { return array_intersect($namespace['commands'], array_keys($commands)); - }, $namespaces))); + }, $namespaces)))); if ($describedNamespace) { $this->writeText(sprintf('Available commands for the "%s" namespace:', $describedNamespace), $options); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index ea5ebf1ddd5a..170a0edc8aab 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -258,13 +258,13 @@ public function setRemovingPasses(array $passes) */ private function sortPasses(array $passes) { - if (0 === count($passes)) { + if (0 === \count($passes)) { return array(); } krsort($passes); // Flatten the array - return call_user_func_array('array_merge', $passes); + return array_merge(...$passes); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php index 97b083fa13c3..4f440af7f93a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -47,7 +47,7 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container if ($services) { krsort($services); - $services = call_user_func_array('array_merge', $services); + $services = array_merge(...$services); } return $services; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PassConfigTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PassConfigTest.php index d9444ca89cf3..46ec1ab12efa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PassConfigTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PassConfigTest.php @@ -35,4 +35,20 @@ public function testPassOrdering() $this->assertSame($pass2, $passes[0]); $this->assertSame($pass1, $passes[1]); } + + public function testPassOrderingWithoutPasses() + { + $config = new PassConfig(); + $config->setBeforeOptimizationPasses(array()); + $config->setAfterRemovingPasses(array()); + $config->setBeforeRemovingPasses(array()); + $config->setOptimizationPasses(array()); + $config->setRemovingPasses(array()); + + $this->assertEmpty($config->getBeforeOptimizationPasses()); + $this->assertEmpty($config->getAfterRemovingPasses()); + $this->assertEmpty($config->getBeforeRemovingPasses()); + $this->assertEmpty($config->getOptimizationPasses()); + $this->assertEmpty($config->getRemovingPasses()); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php index 61e3fa947a47..dffc9b97ee12 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -78,6 +78,13 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder() $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container)); } + + public function testWithEmptyArray() + { + $container = new ContainerBuilder(); + $priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation(); + $this->assertEquals(array(), $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container)); + } } class PriorityTaggedServiceTraitImplementation diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php index a50ce7763bd8..e01c21326d45 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php @@ -1,7 +1,6 @@ $handlers) { krsort($handlersByMessage[$message]); - $handlersByMessage[$message] = \call_user_func_array('array_merge', $handlersByMessage[$message]); + $handlersByMessage[$message] = array_merge(...$handlersByMessage[$message]); } $definitions = array();