Skip to content
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

Optimize array_merge #302

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/CompositeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions tests/Benchmark/ContainerBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
);
}

Expand Down