Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
1 changed file
with
11 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,21 +217,18 @@ public function has($id) | |
*/ | ||
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1) | ||
{ | ||
if (isset($this->aliases[$id])) { | ||
$id = $this->aliases[$id]; | ||
} | ||
|
||
// Re-use shared service instance if it exists. | ||
if (isset($this->services[$id])) { | ||
return $this->services[$id]; | ||
} | ||
if ('service_container' === $id) { | ||
return $this; | ||
} | ||
if (isset($this->factories[$id])) { | ||
return $this->factories[$id](); | ||
} | ||
return $this->services[$id] | ||
?? $this->services[$id = $this->aliases[$id] ?? $id] | ||
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? array($this, 'make'))($id, $invalidBehavior)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nicolas-grekas
Member
|
||
} | ||
|
||
/** | ||
* Creates a service. | ||
* | ||
* As a separate method to allow "get()" to use the really fast `??` operator. | ||
*/ | ||
private function make(string $id, int $invalidBehavior) | ||
{ | ||
if (isset($this->loading[$id])) { | ||
throw new ServiceCircularReferenceException($id, array_keys($this->loading)); | ||
} | ||
|
There is some reason to keep PHP 5.4 compatibility (
array
vs[]
) and using incompatible??
from PHP 7?Symfony team plans to upgrade to array short syntax anytime?