From ef41f136f842b6b47f3c9b83418f436dc36b0af0 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 1 Dec 2014 18:05:10 +0100 Subject: [PATCH] Literals on rule are now public This causes a reduction of ~500k function calls for packagist composer update (~14 million total). --- src/Composer/DependencyResolver/Rule.php | 8 ++------ src/Composer/DependencyResolver/RuleWatchGraph.php | 2 +- src/Composer/DependencyResolver/RuleWatchNode.php | 4 ++-- src/Composer/DependencyResolver/Solver.php | 14 +++++++------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index a47038431..e592e3c16 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -32,7 +32,6 @@ class Rule protected $pool; protected $disabled; - protected $literals; protected $type; protected $id; protected $reason; @@ -42,6 +41,8 @@ class Rule protected $ruleHash; + public $literals; + public function __construct(Pool $pool, array $literals, $reason, $reasonData, $job = null) { $this->pool = $pool; @@ -160,11 +161,6 @@ class Rule return !$this->disabled; } - public function getLiterals() - { - return $this->literals; - } - public function isAssertion() { return 1 === count($this->literals); diff --git a/src/Composer/DependencyResolver/RuleWatchGraph.php b/src/Composer/DependencyResolver/RuleWatchGraph.php index a9f7414b2..2360c5219 100644 --- a/src/Composer/DependencyResolver/RuleWatchGraph.php +++ b/src/Composer/DependencyResolver/RuleWatchGraph.php @@ -95,7 +95,7 @@ class RuleWatchGraph $otherWatch = $node->getOtherWatch($literal); if (!$node->getRule()->isDisabled() && !$decisions->satisfy($otherWatch)) { - $ruleLiterals = $node->getRule()->getLiterals(); + $ruleLiterals = $node->getRule()->literals; $alternativeLiterals = array_filter($ruleLiterals, function ($ruleLiteral) use ($literal, $otherWatch, $decisions) { return $literal !== $ruleLiteral && diff --git a/src/Composer/DependencyResolver/RuleWatchNode.php b/src/Composer/DependencyResolver/RuleWatchNode.php index 59482ffdb..cdbf6a00b 100644 --- a/src/Composer/DependencyResolver/RuleWatchNode.php +++ b/src/Composer/DependencyResolver/RuleWatchNode.php @@ -35,7 +35,7 @@ class RuleWatchNode { $this->rule = $rule; - $literals = $rule->getLiterals(); + $literals = $rule->literals; $this->watch1 = count($literals) > 0 ? $literals[0] : 0; $this->watch2 = count($literals) > 1 ? $literals[1] : 0; @@ -51,7 +51,7 @@ class RuleWatchNode */ public function watch2OnHighest(Decisions $decisions) { - $literals = $this->rule->getLiterals(); + $literals = $this->rule->literals; // if there are only 2 elements, both are being watched anyway if (count($literals) < 3) { diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 36b1d9862..3d9249b05 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -62,7 +62,7 @@ class Solver continue; } - $literals = $rule->getLiterals(); + $literals = $rule->literals; $literal = $literals[0]; if (!$this->decisions->decided(abs($literal))) { @@ -104,7 +104,7 @@ class Solver continue; } - $assertRuleLiterals = $assertRule->getLiterals(); + $assertRuleLiterals = $assertRule->literals; $assertRuleLiteral = $assertRuleLiterals[0]; if (abs($literal) !== abs($assertRuleLiteral)) { @@ -356,7 +356,7 @@ class Solver while (true) { $this->learnedPool[count($this->learnedPool) - 1][] = $rule; - foreach ($rule->getLiterals() as $literal) { + foreach ($rule->literals as $literal) { // skip the one true literal if ($this->decisions->satisfy($literal)) { continue; @@ -480,7 +480,7 @@ class Solver $this->problems[] = $problem; $seen = array(); - $literals = $conflictRule->getLiterals(); + $literals = $conflictRule->literals; foreach ($literals as $literal) { // skip the one true literal @@ -503,7 +503,7 @@ class Solver $problem->addRule($why); $this->analyzeUnsolvableRule($problem, $why); - $literals = $why->getLiterals(); + $literals = $why->literals; foreach ($literals as $literal) { // skip the one true literal @@ -627,7 +627,7 @@ class Solver $decisionQueue = array(); $noneSatisfied = true; - foreach ($rule->getLiterals() as $literal) { + foreach ($rule->literals as $literal) { if ($this->decisions->satisfy($literal)) { $noneSatisfied = false; break; @@ -688,7 +688,7 @@ class Solver } $rule = $this->rules->ruleById($i); - $literals = $rule->getLiterals(); + $literals = $rule->literals; if ($rule->isDisabled()) { continue;