Skip to content

Commit

Permalink
[DI] Minor performance tweak in PriorityTaggedServiceTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Iltar van der Berg authored and nicolas-grekas committed May 4, 2018
1 parent e6f99da commit 94314f9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion link
Expand Up @@ -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)));

Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
Expand Up @@ -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));
}

/**
Expand Down
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Expand Up @@ -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('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
Expand Down
Expand Up @@ -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);
}
}
Expand Up @@ -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;
Expand Down
Expand Up @@ -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());
}
}
Expand Up @@ -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
Expand Down
@@ -1,7 +1,6 @@
<?php

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

class ProjectExtension implements ExtensionInterface
Expand All @@ -12,7 +11,7 @@ public function load(array $configs, ContainerBuilder $configuration)
$configs = array_filter($configs);

if ($configs) {
$config = call_user_func_array('array_merge', $configs);
$config = array_merge(...$configs);
} else {
$config = array();
}
Expand Down
Expand Up @@ -100,7 +100,7 @@ private function registerHandlers(ContainerBuilder $container)

foreach ($handlersByMessage as $message => $handlers) {
krsort($handlersByMessage[$message]);
$handlersByMessage[$message] = \call_user_func_array('array_merge', $handlersByMessage[$message]);
$handlersByMessage[$message] = array_merge(...$handlersByMessage[$message]);
}

$definitions = array();
Expand Down

0 comments on commit 94314f9

Please sign in to comment.