8000 minor #26161 [DI] Top micro benchmarks (nicolas-grekas) · symfony/symfony@4d6c481 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d6c481

Browse files
committed
minor #26161 [DI] Top micro benchmarks (nicolas-grekas)
This PR was merged into the 4.1-dev branch. Discussion ---------- [DI] Top micro benchmarks | 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 makes Symfony rank 1st most of the time, 2nd within the margin error otherwise. Follow up of kocsismate/php-di-container-benchmarks#21 Commits ------- 3edf5f1 [DI] Top micro benchmarks
2 parents 4ef0b3e + 3edf5f1 commit 4d6c481

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,18 @@ public function has($id)
217217
*/
218218
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
219219
{
220-
if (isset($this->aliases[$id])) {
221-
$id = $this->aliases[$id];
222-
}
223-
224-
// Re-use shared service instance if it exists.
225-
if (isset($this->services[$id])) {
226-
return $this->services[$id];
227-
}
228-
if ('service_container' === $id) {
229-
return $this;
230-
}
231-
if (isset($this->factories[$id])) {
232-
return $this->factories[$id]();
233-
}
220+
return $this->services[$id]
221+
?? $this->services[$id = $this->aliases[$id] ?? $id]
222+
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? array($this, 'make'))($id, $invalidBehavior));
223+
}
234224

225+
/**
226+
* Creates a service.
227+
*
228+
* As a separate method to allow "get()" to use the really fast `??` operator.
229+
*/
230+
private function make(string $id, int $invalidBehavior)
231+
{
235232
if (isset($this->loading[$id])) {
236233
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
237234
}

0 commit comments

Comments
 (0)
0