minor #21492 [DI] Deduplicate resources while adding them (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Deduplicate resources while adding them

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Since the string cast of resources is already used to deduplicate them, let's do it earlier. This can only decrease memory usage.

Commits
-------

04853fc5c3 [DI] Deduplicate resource while adding them
This commit is contained in:
Fabien Potencier 2017-02-01 11:11:51 -08:00
commit 29db096b0b

View File

@ -202,7 +202,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*/ */
public function getResources() public function getResources()
{ {
return array_unique($this->resources); return array_values($this->resources);
} }
/** /**
@ -218,7 +218,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
return $this; return $this;
} }
$this->resources[] = $resource; $this->resources[(string) $resource] = $resource;
return $this; return $this;
} }