1
0
Fork 0

Make ruleById lookup table in rule set public

Saves about 500k function calls on a packagist update
pull/3481/head
Nils Adermann 2014-12-01 18:28:45 +01:00
parent 5c0efdcaa2
commit d77400ade2
3 changed files with 10 additions and 9 deletions

View File

@ -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;

View File

@ -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()) {

View File

@ -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()