Skip to content

Commit 7fbf475

Browse files
committed
Move array_merge calls out of loops to improve performance
1 parent 9139475 commit 7fbf475

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

DependencyInjection/Configuration.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,15 +1262,13 @@ private function addLockSection(ArrayNodeDefinition $rootNode, callable $enableI
12621262
->then(function ($v) {
12631263
$resources = [];
12641264
foreach ($v as $resource) {
1265-
$resources = array_merge_recursive(
1266-
$resources,
1267-
\is_array($resource) && isset($resource['name'])
1268-
? [$resource['name'] => $resource['value']]
1269-
: ['default' => $resource]
1270-
);
1265+
$resources[] = \is_array($resource) && isset($resource['name'])
1266+
? [$resource['name'] => $resource['value']]
1267+
: ['default' => $resource]
1268+
;
12711269
}
12721270

1273-
return $resources;
1271+
return array_merge_recursive([], ...$resources);
12741272
})
12751273
->end()
12761274
->prototype('array')

Tests/CacheWarmer/SerializerCacheWarmerTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1616
use Symfony\Component\Cache\Adapter\NullAdapter;
1717
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
18+
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
1819
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
1920
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
2021

2122
class SerializerCacheWarmerTest extends TestCase
2223
{
23-
public function testWarmUp()
24+
/**
25+
* @dataProvider loaderProvider
26+
*/
27+
public function testWarmUp(array $loaders)
2428
{
25-
$loaders = [
26-
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
27-
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
28-
];
29-
3029
$file = sys_get_temp_dir().'/cache-serializer.php';
3130
@unlink($file);
3231

@@ -41,6 +40,26 @@ public function testWarmUp()
4140
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
4241
}
4342

43+
public function loaderProvider()
44+
{
45+
return [
46+
[
47+
[
48+
new LoaderChain([
49+
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
50+
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
51+
]),
52+
],
53+
],
54+
[
55+
[
56+
new XmlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/person.xml'),
57+
new YamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/author.yml'),
58+
],
59+
],
60+
];
61+
}
62+
4463
public function testWarmUpWithoutLoader()
4564
{
4665
$file = sys_get_temp_dir().'/cache-serializer-without-loader.php';

0 commit comments

Comments
 (0)