Forráskód Böngészése

Make decisions countable and use foreach to iterate them in solver

Nils Adermann 13 éve
szülő
commit
2fbc04b950

+ 3 - 3
src/Composer/DependencyResolver/Decisions.php

@@ -17,7 +17,7 @@ namespace Composer\DependencyResolver;
  *
  * @author Nils Adermann <naderman@naderman.de>
  */
-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()

+ 4 - 9
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