Improve memory usage resolving dependencies II
Optimize `rulesByHash` in `Composer\DependencyResolver\RuleSet` to only use an array with the second element, event with very low probability.pull/6168/head
parent
4e1887a721
commit
8fccbaa4a4
|
@ -63,8 +63,14 @@ class RuleSet implements \IteratorAggregate, \Countable
|
||||||
// Do not add if rule already exists
|
// Do not add if rule already exists
|
||||||
if (isset($this->rulesByHash[$hash])) {
|
if (isset($this->rulesByHash[$hash])) {
|
||||||
$potentialDuplicates = $this->rulesByHash[$hash];
|
$potentialDuplicates = $this->rulesByHash[$hash];
|
||||||
foreach ($potentialDuplicates as $potentialDuplicate) {
|
if (is_array($potentialDuplicates)) {
|
||||||
if ($rule->equals($potentialDuplicate)) {
|
foreach ($potentialDuplicates as $potentialDuplicate) {
|
||||||
|
if ($rule->equals($potentialDuplicate)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($rule->equals($potentialDuplicates)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,9 +87,12 @@ class RuleSet implements \IteratorAggregate, \Countable
|
||||||
$this->nextRuleId++;
|
$this->nextRuleId++;
|
||||||
|
|
||||||
if (!isset($this->rulesByHash[$hash])) {
|
if (!isset($this->rulesByHash[$hash])) {
|
||||||
$this->rulesByHash[$hash] = array($rule);
|
$this->rulesByHash[$hash] = $rule;
|
||||||
} else {
|
} elseif (is_array($this->rulesByHash[$hash])) {
|
||||||
$this->rulesByHash[$hash][] = $rule;
|
$this->rulesByHash[$hash][] = $rule;
|
||||||
|
} else {
|
||||||
|
$originalRule = $this->rulesByHash[$hash];
|
||||||
|
$this->rulesByHash[$hash] = array($originalRule, $rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue