Skip to content

Commit 4c08b07

Browse files
committed
minor #29309 Optimize perf by replacing call_user_func with dynamic variables (ostrolucky)
This PR was merged into the 4.1 branch. Discussion ---------- Optimize perf by replacing call_user_func with dynamic variables | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This provides similar boost as in #29245, but on more places and without complexity increase. Check eg. https://github.com/fab2s/call_user_func for proof Fabpot failure unrelated Commits ------- 0c6ef01 Optimize perf by replacing call_user_func with dynamic vars
2 parents c600de0 + 0c6ef01 commit 4c08b07

File tree

54 files changed

+79
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+79
-79
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function configureOptions(OptionsResolver $resolver)
212212
// for equal query builders
213213
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
214214
if (\is_callable($queryBuilder)) {
215-
$queryBuilder = \call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
215+
$queryBuilder = $queryBuilder($options['em']->getRepository($options['class']));
216216
}
217217

218218
return $queryBuilder;

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function configureOptions(OptionsResolver $resolver)
2929
// for equal query builders
3030
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
3131
if (\is_callable($queryBuilder)) {
32-
$queryBuilder = \call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
32+
$queryBuilder = $queryBuilder($options['em']->getRepository($options['class']));
3333

3434
if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
3535
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');

src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function formatRecord(array $record)
102102
{
103103
if ($this->processors) {
104104
foreach ($this->processors as $processor) {
105-
$record = \call_user_func($processor, $record);
105+
$record = $processor($record);
106106
}
107107
}
108108

src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function instantiateProxy(ContainerInterface $container, Definition $defi
5151
return $this->factory->createProxy(
5252
$definition->getClass(),
5353
function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) {
54-
$wrappedInstance = \call_user_func($realInstantiator);
54+
$wrappedInstance = $realInstantiator();
5555

5656
$proxy->setProxyInitializer(null);
5757

src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ class PhpArrayAdapterWrapper extends PhpArrayAdapter
122122
{
123123
public function save(CacheItemInterface $item)
124124
{
125-
\call_user_func(\Closure::bind(function () use ($item) {
125+
(\Closure::bind(function () use ($item) {
126126
$this->values[$item->getKey()] = $item->get();
127127
$this->warmUp($this->values);
128128
$this->values = eval(substr(file_get_contents($this->file), 6));
129-
}, $this, PhpArrayAdapter::class));
129+
}, $this, PhpArrayAdapter::class))();
130130

131131
return true;
132132
}

src/Symfony/Component/Cache/Tests/CacheItemTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public function testTag()
5959
$this->assertSame($item, $item->tag('foo'));
6060
$this->assertSame($item, $item->tag(array('bar', 'baz')));
6161

62-
\call_user_func(\Closure::bind(function () use ($item) {
62+
(\Closure::bind(function () use ($item) {
6363
$this->assertSame(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), $item->tags);
64-
}, $this, CacheItem::class));
64+
}, $this, CacheItem::class))();
6565
}
6666

6767
/**

src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ class PhpArrayCacheWrapper extends PhpArrayCache
116116
{
117117
public function set($key, $value, $ttl = null)
118118
{
119-
\call_user_func(\Closure::bind(function () use ($key, $value) {
119+
(\Closure::bind(function () use ($key, $value) {
120120
$this->values[$key] = $value;
121121
$this->warmUp($this->values);
122122
$this->values = eval(substr(file_get_contents($this->file), 6));
123-
}, $this, PhpArrayCache::class));
123+
}, $this, PhpArrayCache::class))();
124124

125125
return true;
126126
}
@@ -130,13 +130,13 @@ public function setMultiple($values, $ttl = null)
130130
if (!\is_array($values) && !$values instanceof \Traversable) {
131131
return parent::setMultiple($values, $ttl);
132132
}
133-
\call_user_func(\Closure::bind(function () use ($values) {
133+
(\Closure::bind(function () use ($values) {
134134
foreach ($values as $key => $value) {
135135
$this->values[$key] = $value;
136136
}
137137
$this->warmUp($this->values);
138138
$this->values = eval(substr(file_get_contents($this->file), 6));
139-
}, $this, PhpArrayCache::class));
139+
}, $this, PhpArrayCache::class))();
140140

141141
return true;
142142
}

src/Symfony/Component/Config/ConfigCacheFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function cache($file, $callback)
4343

4444
$cache = new ConfigCache($file, $this->debug);
4545
if (!$cache->isFresh()) {
46-
\call_user_func($callback, $cache);
46+
$callback($cache);
4747
}
4848

4949
return $cache;

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ private function generateSignature(\ReflectionClass $class)
154154

155155
if (interface_exists(EventSubscriberInterface::class, false) && $class->isSubclassOf(EventSubscriberInterface::class)) {
156156
yield EventSubscriberInterface::class;
157-
yield print_r(\call_user_func(array($class->name, 'getSubscribedEvents')), true);
157+
yield print_r($class->name::getSubscribedEvents(), true);
158158
}
159159

160160
if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) {
161161
yield ServiceSubscriberInterface::class;
162-
yield print_r(\call_user_func(array($class->name, 'getSubscribedServices')), true);
162+
yield print_r($class->name::getSubscribedServices(), true);
163163
}
164164
}
165165
}

src/Symfony/Component/Config/ResourceCheckerConfigCacheFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function cache($file, $callback)
4040

4141
$cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
4242
if (!$cache->isFresh()) {
43-
\call_user_func($callback, $cache);
43+
$callback($cache);
4444
}
4545

4646
return $cache;

0 commit comments

Comments
 (0)