-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Improve performance of the generated code. #9432
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ private function addServiceLocalTempVariables($cId, $definition) | |
$this->getServiceCallsFromArguments($iDefinition->getArguments(), $calls, $behavior); | ||
$this->getServiceCallsFromArguments($iDefinition->getMethodCalls(), $calls, $behavior); | ||
$this->getServiceCallsFromArguments($iDefinition->getProperties(), $calls, $behavior); | ||
$this->getServiceCallsFromArguments(array($iDefinition->getConfigurator()), $calls, $behavior); | ||
} | ||
|
||
$code = ''; | ||
|
@@ -482,10 +483,24 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta | |
|
||
if (is_array($callable)) { | ||
if ($callable[0] instanceof Reference) { | ||
return sprintf(" %s->%s(\$%s);\n", $this->getServiceCall((string) $callable[0]), $callable[1], $variableName); | ||
return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
} | ||
|
||
return sprintf(" call_user_func(array(%s, '%s'), \$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
if ($callable[0] instanceof Definition) { | ||
if ($this->definitionVariables->contains($callable[0])) { | ||
return sprintf(" %s->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
} elseif (version_compare(PHP_VERSION, '5.4.0') >= 0) { | ||
return sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works for complex Definition (i.e. involving some method call rather than just a constructor) |
||
} | ||
} | ||
|
||
$class = $this->dumpValue($callable[0]); | ||
// If the class is a string we can optimize call_user_func away | ||
if (strpos($class, "'") === 0) { | ||
return sprintf(" %s::%s(\$%s);\n", substr($class, 1, -1), $callable[1], $variableName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks wrong to me because dumping the value will escape |
||
} | ||
|
||
return sprintf(" call_user_func(array(%s, '%s'), \$%s);\n", $class, $callable[1], $variableName); | ||
} | ||
|
||
return sprintf(" %s(\$%s);\n", $callable, $variableName); | ||
|
@@ -689,7 +704,13 @@ private function addNewInstance($id, Definition $definition, $return, $instantia | |
|
||
if (null !== $definition->getFactoryMethod()) { | ||
if (null !== $definition->getFactoryClass()) { | ||
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : ''); | ||
$class = $this->dumpValue($definition->getFactoryClass()); | ||
|
||
// If the class is a string we can optimize call_user_func away | ||
if (strpos($class, "'") === 0) { | ||
return sprintf(" $return{$instantiation}%s::%s(%s);\n", substr($class, 1, -1), $definition->getFactoryMethod(), $arguments ? implode(', ', $arguments) : ''); | ||
} | ||
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $class, $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : ''); | ||
} | ||
|
||
if (null !== $definition->getFactoryService()) { | ||
|
@@ -1070,7 +1091,8 @@ private function getInlinedDefinitions(Definition $definition) | |
$definitions = array_merge( | ||
$this->getDefinitionsFromArguments($definition->getArguments()), | ||
$this->getDefinitionsFromArguments($definition->getMethodCalls()), | ||
$this->getDefinitionsFromArguments($definition->getProperties()) | ||
$this->getDefinitionsFromArguments($definition->getProperties()), | ||
$this->getDefinitionsFromArguments(array($definition->getConfigurator())) | ||
); | ||
|
||
$this->inlinedDefinitions->offsetSet($definition, $definitions); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
is enough as the previousif
returns