From d77400ade29b087e4d0a726859d7760fd3c971c8 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 1 Dec 2014 18:28:45 +0100 Subject: [PATCH] Make ruleById lookup table in rule set public Saves about 500k function calls on a packagist update --- src/Composer/DependencyResolver/RuleSet.php | 13 +++++++------ src/Composer/DependencyResolver/Solver.php | 4 ++-- .../Test/DependencyResolver/RuleSetTest.php | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Composer/DependencyResolver/RuleSet.php b/src/Composer/DependencyResolver/RuleSet.php index 05ab780ac..1b72204a0 100644 --- a/src/Composer/DependencyResolver/RuleSet.php +++ b/src/Composer/DependencyResolver/RuleSet.php @@ -22,6 +22,13 @@ class RuleSet implements \IteratorAggregate, \Countable const TYPE_JOB = 1; const TYPE_LEARNED = 4; + /** + * Lookup table for rule id to rule object + * + * @var array + */ + public $ruleById; + protected static $types = array( -1 => 'UNKNOWN', self::TYPE_PACKAGE => 'PACKAGE', @@ -30,7 +37,6 @@ class RuleSet implements \IteratorAggregate, \Countable ); protected $rules; - protected $ruleById; protected $nextRuleId; protected $rulesByHash; @@ -76,11 +82,6 @@ class RuleSet implements \IteratorAggregate, \Countable return $this->nextRuleId; } - public function ruleById($id) - { - return $this->ruleById[$id]; - } - public function getRules() { return $this->rules; diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 9dc375787..c9a4d5882 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -56,7 +56,7 @@ class Solver $rulesCount = count($this->rules); for ($ruleIndex = 0; $ruleIndex < $rulesCount; $ruleIndex++) { - $rule = $this->rules->ruleById($ruleIndex); + $rule = $this->rules->ruleById[$ruleIndex]; if (!$rule->isAssertion() || $rule->isDisabled()) { continue; @@ -687,7 +687,7 @@ class Solver $i = 0; } - $rule = $this->rules->ruleById($i); + $rule = $this->rules->ruleById[$i]; $literals = $rule->literals; if ($rule->isDisabled()) { diff --git a/tests/Composer/Test/DependencyResolver/RuleSetTest.php b/tests/Composer/Test/DependencyResolver/RuleSetTest.php index 35e3f17d6..a124aef60 100644 --- a/tests/Composer/Test/DependencyResolver/RuleSetTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleSetTest.php @@ -76,7 +76,7 @@ class RuleSetTest extends TestCase $rule = new Rule($this->pool, array(), 'job1', null); $ruleSet->add($rule, RuleSet::TYPE_JOB); - $this->assertSame($rule, $ruleSet->ruleById(0)); + $this->assertSame($rule, $ruleSet->ruleById[0]); } public function testGetIterator()