1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 08:32:56 +00:00

Reduce calls on Rule::getHash()

This commit is contained in:
Yanick Witschi 2016-09-30 15:06:22 +02:00
parent 00c1b601c8
commit 4a769a785c
3 changed files with 42 additions and 58 deletions

View file

@ -62,13 +62,24 @@ class RuleSet implements \IteratorAggregate, \Countable
$this->rules[$type] = array();
}
$hash = $rule->getHash();
// Do not add if rule already exists
if (isset($this->rulesByHash[$hash])) {
$potentialDuplicates = $this->rulesByHash[$hash];
foreach ($potentialDuplicates as $potentialDuplicate) {
if ($rule->equals($potentialDuplicate)) {
return;
}
}
}
$this->rules[$type][] = $rule;
$this->ruleById[$this->nextRuleId] = $rule;
$rule->setType($type);
$this->nextRuleId++;
$hash = $rule->getHash();
if (!isset($this->rulesByHash[$hash])) {
$this->rulesByHash[$hash] = array($rule);
} else {
@ -135,20 +146,6 @@ class RuleSet implements \IteratorAggregate, \Countable
return array_keys($types);
}
public function containsEqual($rule)
{
if (isset($this->rulesByHash[$rule->getHash()])) {
$potentialDuplicates = $this->rulesByHash[$rule->getHash()];
foreach ($potentialDuplicates as $potentialDuplicate) {
if ($rule->equals($potentialDuplicate)) {
return true;
}
}
}
return false;
}
public function getPrettyString(Pool $pool = null)
{
$string = "\n";

View file

@ -137,7 +137,7 @@ class RuleSetGenerator
*/
private function addRule($type, Rule $newRule = null)
{
if (!$newRule || $this->rules->containsEqual($newRule)) {
if (!$newRule) {
return;
}