1
0
Fork 0

Literals on rule are now public

This causes a reduction of ~500k function calls for packagist composer
update (~14 million total).
pull/3481/head
Nils Adermann 2014-12-01 18:05:10 +01:00
parent 5333017aea
commit ef41f136f8
4 changed files with 12 additions and 16 deletions

View File

@ -32,7 +32,6 @@ class Rule
protected $pool; protected $pool;
protected $disabled; protected $disabled;
protected $literals;
protected $type; protected $type;
protected $id; protected $id;
protected $reason; protected $reason;
@ -42,6 +41,8 @@ class Rule
protected $ruleHash; protected $ruleHash;
public $literals;
public function __construct(Pool $pool, array $literals, $reason, $reasonData, $job = null) public function __construct(Pool $pool, array $literals, $reason, $reasonData, $job = null)
{ {
$this->pool = $pool; $this->pool = $pool;
@ -160,11 +161,6 @@ class Rule
return !$this->disabled; return !$this->disabled;
} }
public function getLiterals()
{
return $this->literals;
}
public function isAssertion() public function isAssertion()
{ {
return 1 === count($this->literals); return 1 === count($this->literals);

View File

@ -95,7 +95,7 @@ class RuleWatchGraph
$otherWatch = $node->getOtherWatch($literal); $otherWatch = $node->getOtherWatch($literal);
if (!$node->getRule()->isDisabled() && !$decisions->satisfy($otherWatch)) { 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) { $alternativeLiterals = array_filter($ruleLiterals, function ($ruleLiteral) use ($literal, $otherWatch, $decisions) {
return $literal !== $ruleLiteral && return $literal !== $ruleLiteral &&

View File

@ -35,7 +35,7 @@ class RuleWatchNode
{ {
$this->rule = $rule; $this->rule = $rule;
$literals = $rule->getLiterals(); $literals = $rule->literals;
$this->watch1 = count($literals) > 0 ? $literals[0] : 0; $this->watch1 = count($literals) > 0 ? $literals[0] : 0;
$this->watch2 = count($literals) > 1 ? $literals[1] : 0; $this->watch2 = count($literals) > 1 ? $literals[1] : 0;
@ -51,7 +51,7 @@ class RuleWatchNode
*/ */
public function watch2OnHighest(Decisions $decisions) 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 there are only 2 elements, both are being watched anyway
if (count($literals) < 3) { if (count($literals) < 3) {

View File

@ -62,7 +62,7 @@ class Solver
continue; continue;
} }
$literals = $rule->getLiterals(); $literals = $rule->literals;
$literal = $literals[0]; $literal = $literals[0];
if (!$this->decisions->decided(abs($literal))) { if (!$this->decisions->decided(abs($literal))) {
@ -104,7 +104,7 @@ class Solver
continue; continue;
} }
$assertRuleLiterals = $assertRule->getLiterals(); $assertRuleLiterals = $assertRule->literals;
$assertRuleLiteral = $assertRuleLiterals[0]; $assertRuleLiteral = $assertRuleLiterals[0];
if (abs($literal) !== abs($assertRuleLiteral)) { if (abs($literal) !== abs($assertRuleLiteral)) {
@ -356,7 +356,7 @@ class Solver
while (true) { while (true) {
$this->learnedPool[count($this->learnedPool) - 1][] = $rule; $this->learnedPool[count($this->learnedPool) - 1][] = $rule;
foreach ($rule->getLiterals() as $literal) { foreach ($rule->literals as $literal) {
// skip the one true literal // skip the one true literal
if ($this->decisions->satisfy($literal)) { if ($this->decisions->satisfy($literal)) {
continue; continue;
@ -480,7 +480,7 @@ class Solver
$this->problems[] = $problem; $this->problems[] = $problem;
$seen = array(); $seen = array();
$literals = $conflictRule->getLiterals(); $literals = $conflictRule->literals;
foreach ($literals as $literal) { foreach ($literals as $literal) {
// skip the one true literal // skip the one true literal
@ -503,7 +503,7 @@ class Solver
$problem->addRule($why); $problem->addRule($why);
$this->analyzeUnsolvableRule($problem, $why); $this->analyzeUnsolvableRule($problem, $why);
$literals = $why->getLiterals(); $literals = $why->literals;
foreach ($literals as $literal) { foreach ($literals as $literal) {
// skip the one true literal // skip the one true literal
@ -627,7 +627,7 @@ class Solver
$decisionQueue = array(); $decisionQueue = array();
$noneSatisfied = true; $noneSatisfied = true;
foreach ($rule->getLiterals() as $literal) { foreach ($rule->literals as $literal) {
if ($this->decisions->satisfy($literal)) { if ($this->decisions->satisfy($literal)) {
$noneSatisfied = false; $noneSatisfied = false;
break; break;
@ -688,7 +688,7 @@ class Solver
} }
$rule = $this->rules->ruleById($i); $rule = $this->rules->ruleById($i);
$literals = $rule->getLiterals(); $literals = $rule->literals;
if ($rule->isDisabled()) { if ($rule->isDisabled()) {
continue; continue;