Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Optimize perf by replacing call_user_func with dynamic variables #29309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function configureOptions(OptionsResolver $resolver)
// for equal query builders
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
if (\is_callable($queryBuilder)) {
$queryBuilder = \call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
$queryBuilder = $queryBuilder($options['em']->getRepository($options['class']));
}

return $queryBuilder;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function configureOptions(OptionsResolver $resolver)
// for equal query builders
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
if (\is_callable($queryBuilder)) {
$queryBuilder = \call_user_func($queryBuilder, $options['em']->getRepository($options['class']));
$queryBuilder = $queryBuilder($options['em']->getRepository($options['class']));

if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Monolog/Handler/ServerLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function formatRecord(array $record)
{
if ($this->processors) {
foreach ($this->processors as $processor) {
$record = \call_user_func($processor, $record);
$record = $processor($record);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function instantiateProxy(ContainerInterface $container, Definition $defi
return $this->factory->createProxy(
$definition->getClass(),
function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) {
$wrappedInstance = \call_user_func($realInstantiator);
$wrappedInstance = $realInstantiator();

$proxy->setProxyInitializer(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ class PhpArrayAdapterWrapper extends PhpArrayAdapter
{
public function save(CacheItemInterface $item)
{
\call_user_func(\Closure::bind(function () use ($item) {
(\Closure::bind(function () use ($item) {
$this->values[$item->getKey()] = $item->get();
$this->warmUp($this->values);
$this->values = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayAdapter::class));
}, $this, PhpArrayAdapter::class))();

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Cache/Tests/CacheItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function testTag()
$this->assertSame($item, $item->tag('foo'));
$this->assertSame($item, $item->tag(array('bar', 'baz')));

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class PhpArrayCacheWrapper extends PhpArrayCache
{
public function set($key, $value, $ttl = null)
{
\call_user_func(\Closure::bind(function () use ($key, $value) {
(\Closure::bind(function () use ($key, $value) {
$this->values[$key] = $value;
$this->warmUp($this->values);
$this->values = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayCache::class));
}, $this, PhpArrayCache::class))();

return true;
}
Expand All @@ -130,13 +130,13 @@ public function setMultiple($values, $ttl = null)
if (!\is_array($values) && !$values instanceof \Traversable) {
return parent::setMultiple($values, $ttl);
}
\call_user_func(\Closure::bind(function () use ($values) {
(\Closure::bind(function () use ($values) {
foreach ($values as $key => $value) {
$this->values[$key] = $value;
}
$this->warmUp($this->values);
$this->values = eval(substr(file_get_contents($this->file), 6));
}, $this, PhpArrayCache::class));
}, $this, PhpArrayCache::class))();

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Config/ConfigCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function cache($file, $callback)

$cache = new ConfigCache($file, $this->debug);
if (!$cache->isFresh()) {
\call_user_func($callback, $cache);
$callback($cache);
}

return $cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ private function generateSignature(\ReflectionClass $class)

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

if (interface_exists(ServiceSubscriberInterface::class, false) && $class->isSubclassOf(ServiceSubscriberInterface::class)) {
yield ServiceSubscriberInterface::class;
yield print_r(\call_user_func(array($class->name, 'getSubscribedServices')), true);
yield print_r($class->name::getSubscribedServices(), true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function cache($file, $callback)

$cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
if (!$cache->isFresh()) {
\call_user_func($callback, $cache);
$callback($cache);
}

return $cache;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Config/Util/XmlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function parse($content, $schemaOrCallable = null)
$e = null;
if (\is_callable($schemaOrCallable)) {
try {
$valid = \call_user_func($schemaOrCallable, $dom, $internalErrors);
$valid = $schemaOrCallable($dom, $internalErrors);
} catch (\Exception $e) {
$valid = false;
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function run(InputInterface $input, OutputInterface $output)
$input->validate();

if ($this->code) {
$statusCode = \call_user_func($this->code, $input, $output);
$statusCode = ($this->code)($input, $output);
} else {
$statusCode = $this->execute($input, $output);
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/ProcessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function wrapCallback(OutputInterface $output, Process $process, callable
$output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));

if (null !== $callback) {
\call_user_func($callback, $type, $buffer);
$callback($type, $buffer);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private function buildLine(): string
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
$callback = function ($matches) {
if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
$text = \call_user_func($formatter, $this, $this->output);
$text = $formatter($this, $this->output);
} elseif (isset($this->messages[$matches[1]])) {
$text = $this->messages[$matches[1]];
} else {
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/ProgressIndicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function display()

$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self) {
if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
return \call_user_func($formatter, $self);
return $formatter($self);
}

return $matches[0];
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Console/Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
}

try {
return \call_user_func($question->getValidator(), $interviewer());
return $question->getValidator()($interviewer());
} catch (RuntimeException $e) {
throw $e;
} catch (\Exception $error) {
Expand Down
10 changes: 5 additions & 5 deletions 10 src/Symfony/Component/CssSelector/XPath/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function nodeToXPath(NodeInterface $node): XPathExpr
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
}

return \call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this);
return $this->nodeTranslators[$node->getNodeName()]($node, $this);
}

/**
Expand All @@ -167,7 +167,7 @@ public function addCombination(string $combiner, NodeInterface $xpath, NodeInter
throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner));
}

return \call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
return $this->combinationTranslators[$combiner]($this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
}

/**
Expand All @@ -179,7 +179,7 @@ public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr
throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName()));
}

return \call_user_func($this->functionTranslators[$function->getName()], $xpath, $function);
return $this->functionTranslators[$function->getName()]($xpath, $function);
}

/**
Expand All @@ -191,7 +191,7 @@ public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr
throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
}

return \call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath);
return $this->pseudoClassTranslators[$pseudoClass]($xpath);
}

/**
Expand All @@ -203,7 +203,7 @@ public function addAttributeMatching(XPathExpr $xpath, string $operator, string
throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator));
}

return \call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value);
return $this->attributeMatchingTranslators[$operator]($xpath, $attribute, $value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function loadClass($class)
require $file;
}
} else {
\call_user_func($this->classLoader, $class);
($this->classLoader)($class);
$file = false;
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public function handleException($exception, array $error = null)
$this->exceptionHandler = null;
try {
if (null !== $exceptionHandler) {
return \call_user_func($exceptionHandler, $exception);
return $exceptionHandler($exception);
}
$handlerException = $handlerException ?: $exception;
} catch (\Throwable $handlerException) {
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function handle(\Exception $exception)
$this->caughtBuffer = null;

try {
\call_user_func($this->handler, $exception);
($this->handler)($exception);
$this->caughtLength = $caughtLength;
} catch (\Exception $e) {
if (!$caughtLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ private function createService(Definition $definition, array &$inlineServices, $
throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', \get_class($service)));
}

\call_user_func($callable, $service);
$callable($service);
}

return $service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class RealServiceInstantiator implements InstantiatorInterface
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
{
return \call_user_func($realInstantiator);
return $realInstantiator();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(ContainerBuilder $container)
*/
public function load($resource, $type = null)
{
\call_user_func($resource, $this->container);
$resource($this->container);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __invoke(Event $event, $eventName, EventDispatcherInterface $dis

$e = $this->stopwatch->start($this->name, 'event_listener');

\call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);
($this->listener)($event, $eventName, $this->dispatcher ?: $dispatcher);

if ($e->isStarted()) {
$e->stop();
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function doDispatch($listeners, $eventName, Event $event)
if ($event->isPropagationStopped()) {
break;
}
\call_user_func($listener, $event, $eventName, $this);
$listener($event, $eventName, $this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function accept()
$fileinfo = $this->current();

foreach ($this->filters as $filter) {
if (false === \call_user_func($filter, $fileinfo)) {
if (false === $filter($fileinfo)) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Form/CallbackTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(callable $transform, callable $reverseTransform)
*/
public function transform($data)
{
return \call_user_func($this->transform, $data);
return ($this->transform)($data);
}

/**
Expand All @@ -57,6 +57,6 @@ public function transform($data)
*/
public function reverseTransform($data)
{
return \call_user_func($this->reverseTransform, $data);
return ($this->reverseTransform)($data);
}
}
4 changes: 2 additions & 2 deletions 4 src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function getValuesForChoices(array $choices)
$givenValues = array();

foreach ($choices as $i => $givenChoice) {
$givenValues[$i] = (string) \call_user_func($this->valueCallback, $givenChoice);
$givenValues[$i] = (string) ($this->valueCallback)($givenChoice);
}

return array_intersect($givenValues, array_keys($this->choices));
Expand Down Expand Up @@ -202,7 +202,7 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$keysByVa
continue;
}

$choiceValue = (string) \call_user_func($value, $choice);
$choiceValue = (string) $value($choice);
$choicesByValues[$choiceValue] = $choice;
$keysByValues[$choiceValue] = $key;
$structuredValues[$key] = $choiceValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
// $value may be an integer or a string, since it's stored in the array
// keys. We want to guarantee it's a string though.
$key = $keys[$value];
$nextIndex = \is_int($index) ? $index++ : \call_user_func($index, $choice, $key, $value);
$nextIndex = \is_int($index) ? $index++ : $index($choice, $key, $value);

// BC normalize label to accept a false value
if (null === $label) {
Expand All @@ -127,7 +127,7 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
} elseif (false !== $label) {
// If "choice_label" is set to false and "expanded" is true, the value false
// should be passed on to the "label" option of the checkboxes/radio buttons
$dynamicLabel = \call_user_func($label, $choice, $key, $value);
$dynamicLabel = $label($choice, $key, $value);
$label = false === $dynamicLabel ? false : (string) $dynamicLabel;
}

Expand All @@ -137,11 +137,11 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
$label,
// The attributes may be a callable or a mapping from choice indices
// to nested arrays
\is_callable($attr) ? \call_user_func($attr, $choice, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array())
\is_callable($attr) ? $attr($choice, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array())
);

// $isPreferred may be null if no choices are preferred
if ($isPreferred && \call_user_func($isPreferred, $choice, $key, $value)) {
if ($isPreferred && $isPreferred($choice, $key, $value)) {
$preferredViews[$nextIndex] = $view;
} else {
$otherViews[$nextIndex] = $view;
Expand Down Expand Up @@ -200,7 +200,7 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key

private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews)
{
$groupLabel = \call_user_func($groupBy, $choice, $keys[$value], $value);
$groupLabel = $groupBy($choice, $keys[$value], $value);

if (null === $groupLabel) {
// If the callable returns null, don't group the choice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function loadChoiceList($value = null)
return $this->choiceList;
}

return $this->choiceList = new ArrayChoiceList(\call_user_func($this->callback), $value);
return $this->choiceList = new ArrayChoiceList(($this->callback)(), $value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function onSubmit(FormEvent $event)
/** @var FormInterface $child */
foreach ($form as $name => $child) {
$isNew = !isset($previousData[$name]);
$isEmpty = \is_callable($this->deleteEmpty) ? \call_user_func($this->deleteEmpty, $child->getData()) : $child->isEmpty();
$isEmpty = \is_callable($this->deleteEmpty) ? ($this->deleteEmpty)($child->getData()) : $child->isEmpty();

// $isNew can only be true if allowAdd is true, so we don't
// need to check allowAdd again
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.