diff --git a/CHANGELOG.md b/CHANGELOG.md index 580cf99f..54e0cadc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.0.3 under development -- no changes in this release. +- Enh #302: Improve performance collecting tags (samdark) ## 1.0.2 February 14, 2022 diff --git a/src/CompositeContainer.php b/src/CompositeContainer.php index fe7d4153..e9e41a2f 100644 --- a/src/CompositeContainer.php +++ b/src/CompositeContainer.php @@ -65,11 +65,12 @@ public function get($id) } if ($container->has($id)) { /** @psalm-suppress MixedArgument Container::get() always return array for tag */ - $tags = array_merge($container->get($id), $tags); + array_unshift($tags, $container->get($id)); } } - return $tags; + /** @psalm-suppress MixedArgument Container::get() always return array for tag */ + return array_merge(...$tags); } foreach ($this->containers as $container) { diff --git a/tests/Benchmark/ContainerBench.php b/tests/Benchmark/ContainerBench.php index 51252ab3..3805eeef 100644 --- a/tests/Benchmark/ContainerBench.php +++ b/tests/Benchmark/ContainerBench.php @@ -79,51 +79,51 @@ public function before(): void // We attach the dummy containers multiple times, to see what would happen if we have lots of them. $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions2) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions3) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions2) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions3) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions2) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions3) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions2) - ) + ) ); $this->composite->attach( new Container( - ContainerConfig::create() + ContainerConfig::create() ->withDefinitions($definitions3) - ) + ) ); }