diff --git a/src/Composer/DependencyResolver/Decisions.php b/src/Composer/DependencyResolver/Decisions.php index 33e0fb27f..cf4419e55 100644 --- a/src/Composer/DependencyResolver/Decisions.php +++ b/src/Composer/DependencyResolver/Decisions.php @@ -17,7 +17,7 @@ namespace Composer\DependencyResolver; * * @author Nils Adermann */ -class Decisions implements \Iterator +class Decisions implements \Iterator, \Countable { const DECISION_LITERAL = 0; const DECISION_REASON = 1; @@ -178,9 +178,9 @@ class Decisions implements \Iterator array_pop($this->decisionQueue); } - public function getMaxOffset() + public function count() { - return count($this->decisionQueue) - 1; + return count($this->decisionQueue); } public function rewind() diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 971f69cfb..e726e0961 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -48,7 +48,7 @@ class Solver // aka solver_makeruledecisions private function makeAssertionRuleDecisions() { - $decisionStart = $this->decisions->getMaxOffset(); + $decisionStart = count($this->decisions) - 1; for ($ruleIndex = 0; $ruleIndex < count($this->rules); $ruleIndex++) { $rule = $this->rules->ruleById($ruleIndex); @@ -242,7 +242,7 @@ class Solver } $this->decisions->revertLast(); - $this->propagateIndex = $this->decisions->getMaxOffset() + 1; + $this->propagateIndex = count($this->decisions); } while (!empty($this->branches)) { @@ -343,7 +343,7 @@ class Solver $seen = array(); $learnedLiterals = array(null); - $decisionId = $this->decisions->getMaxOffset() + 1; + $decisionId = count($this->decisions); $this->learnedPool[] = array(); @@ -483,12 +483,7 @@ class Solver $seen[abs($literal)] = true; } - $decisionId = $this->decisions->getMaxOffset() + 1; - - while ($decisionId > 0) { - $decisionId--; - - $decision = $this->decisions->atOffset($decisionId); + foreach ($this->decisions as $decision) { $literal = $decision[Decisions::DECISION_LITERAL]; // skip literals that are not in this rule