8000 [DI] Minor performance tweak in PriorityTaggedServiceTrait · symfony/symfony@94314f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94314f9

Browse files
Iltar van der Bergnicolas-grekas
Iltar van der Berg
authored andcommitted
[DI] Minor performance tweak in PriorityTaggedServiceTrait
1 parent e6f99da commit 94314f9

File tree

10 files changed

+44
-10
lines changed

10 files changed

+44
-10
lines changed

link

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $sfPackages = array('symfony/symfony' => __DIR__);
3838

3939
$filesystem = new Filesystem();
4040
$braces = array('Bundle', 'Bridge', 'Component', 'Component/Security');
41-
$directories = call_user_func_array('array_merge', array_values(array_map(function ($part) {
41+
$directories = array_merge(...array_values(array_map(function ($part) {
4242
return glob(__DIR__.'/src/Symfony/'.$part.'/*', GLOB_ONLYDIR | GLOB_NOSORT);
4343
}, $braces)));
4444

src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ public function getLogs(/* Request $request = null */)
6464
return $this->records[$hash];
6565
}
6666

67-
return $this->records ? \call_user_func_array('array_merge', $this->records) : array();
67+
if (0 === \count($this->records)) {
68+
return array();
69+
}
70+
71+
return array_merge(...array_values($this->records));
6872
}
6973

7074
/**

src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public function testDebugProcessor()
2929
$this->assertSame(1, $processor->countErrors());
3030
}
3131

32+
public function testDebugProcessorWithoutLogs()
33+
{
34+
$processor = new DebugProcessor();
35+
36+
$this->assertCount(0, $processor->getLogs());
37+
$this->assertSame(0, $processor->countErrors());
38+
}
39+
3240
public function testWithRequestStack()
3341
{
3442
$stack = new RequestStack();

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ protected function describeApplication(Application $application, array $options
210210
}
211211

212212
// calculate max. width based on available commands per namespace
213-
$width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) {
213+
$width = $this->getColumnWidth(array_merge(...array_values(array_map(function ($namespace) use ($commands) {
214214
return array_intersect($namespace['commands'], array_keys($commands));
215-
}, $namespaces)));
215+
}, $namespaces))));
216216

217217
if ($describedNamespace) {
218218
$this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);

src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ public function setRemovingPasses(array $passes)
258258
*/
259259
private function sortPasses(array $passes)
260260
{
261-
if (0 === count($passes)) {
261+
if (0 === \count($passes)) {
262262
return array();
263263
}
264264

265265
krsort($passes);
266266

267267
// Flatten the array
268-
return call_user_func_array('array_merge', $passes);
268+
return array_merge(...$passes);
269269
}
270270
}

src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
4747

48 F438 48
if ($services) {
4949
krsort($services);
50-
$services = call_user_func_array('array_merge', $services);
50+
$services = array_merge(...$services);
5151
}
5252

5353
return $services;

src/Symfony/Component/DependencyInjection/Tests/Compiler/PassConfigTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ public function testPassOrdering()
3535
$this->assertSame($pass2, $passes[0]);
3636
$this->assertSame($pass1, $passes[1]);
3737
}
38+
39+
public function testPassOrderingWithoutPasses()
40+
{
41+
$config = new PassConfig();
42+
$config->setBeforeOptimizationPasses(array());
43+
$config->setAfterRemovingPasses(array());
44+
$config->setBeforeRemovingPasses(array());
45+
$config->setOptimizationPasses(array());
46+
$config->setRemovingPasses(array());
47+
48+
$this->assertEmpty($config->getBeforeOptimizationPasses());
49+
$this->assertEmpty($config->getAfterRemovingPasses());
50+
$this->assertEmpty($config->getBeforeRemovingPasses());
51+
$this->assertEmpty($config->getOptimizationPasses());
52+
$this->assertEmpty($config->getRemovingPasses());
53+
}
3854
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder()
7878

7979
$this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container));
8080
}
81+
82+
public function testWithEmptyArray()
83+
{
84+
$container = new ContainerBuilder();
85+
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
86+
$this->assertEquals(array(), $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container));
87+
}
8188
}
8289

8390
class PriorityTaggedServiceTraitImplementation

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use Symfony\Component\DependencyInjection\ContainerBuilder;
4-
use Symfony\Component\DependencyInjection\Definition;
54
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
65

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

1413
if ($configs) {
15-
$config = call_user_func_array('array_merge', $configs);
14+
$config = array_merge(...$configs);
1615
} else {
1716
$config = array();
1817
}

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function registerHandlers(ContainerBuilder $container)
100100

101101
foreach ($handlersByMessage as $message => $handlers) {
102102
krsort($handlersByMessage[$message]);
103-
$handlersByMessage[$message] = \call_user_func_array('array_merge', $handlersByMessage[$message]);
103+
$handlersByMessage[$message] = array_merge(...$handlersByMessage[$message]);
104104
}
105105

106106
$definitions = array();

0 commit comments

Comments
 (0)
0