Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
#112 #113 removed unused performance optimization loops (too much com…
Browse files Browse the repository at this point in the history
…plexity for too little gain)
  • Loading branch information
Ocramius committed Jun 1, 2016
1 parent f5d9d95 commit a8092a2
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ private function configureAliases(array $aliases)
return;
}

if ($this->mergeNewAliasesIntoOriginalOnes($aliases)) {
// Performance optimization. If there are no collisions, then we don't need to recompute loops
$intersecting = $this->aliases && \array_intersect_key($this->aliases, $aliases);
$this->aliases = $this->aliases ? \array_merge($this->aliases, $aliases) : $aliases;

if ($intersecting) {
$this->resolveAliases($this->aliases);

return;
Expand All @@ -399,32 +403,6 @@ private function configureAliases(array $aliases)
$this->resolveNewAliasesWithPreviouslyResolvedAliases($aliases);
}

/**
* @param array $newAliases
*
* @return bool whether any of the aliases got replaced
*/
private function mergeNewAliasesIntoOriginalOnes(array $newAliases)
{
if (empty($this->aliases)) {
$this->aliases = $newAliases;

return false;
}

$intersect = false;

foreach ($newAliases as $name => $target) {
if (isset($this->aliases[$name])) {
$intersect = true;
}

$this->aliases[$name] = $target;
}

return $intersect;
}

/**
* Add an alias.
*
Expand Down

0 comments on commit a8092a2

Please sign in to comment.