1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 06:42:41 +01:00

Linter performance optimization

Summary: Optimize `ArcanistXHPASTLinterRule::getLintID`.

Test Plan: Compare [[https://secure.phabricator.com/xhprof/profile/PHID-FILE-wwgi4xzupt4z2fvbyff3/?symbol=mpull | before]] and [[https://secure.phabricator.com/xhprof/profile/PHID-FILE-rn2ialomtr2apnkzisb3/?symbol=mpull | after]].

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13541
This commit is contained in:
Joshua Spence 2015-07-07 17:56:12 +10:00
parent d54cb072fa
commit bbccf1dd40
2 changed files with 42 additions and 19 deletions

View file

@ -7,6 +7,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
private $rules = array();
private $lintNameMap;
private $lintSeverityMap;
public function __construct() {
$this->rules = ArcanistXHPASTLinterRule::loadAllRules();
}
@ -37,11 +40,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
}
public function getLintNameMap() {
return mpull($this->rules, 'getLintName', 'getLintID');
if ($this->lintNameMap === null) {
$this->lintNameMap = mpull(
$this->rules,
'getLintName',
'getLintID');
}
return $this->lintNameMap;
}
public function getLintSeverityMap() {
return mpull($this->rules, 'getLintSeverity', 'getLintID');
if ($this->lintSeverityMap === null) {
$this->lintSeverityMap = mpull(
$this->rules,
'getLintSeverity',
'getLintID');
}
return $this->lintSeverityMap;
}
public function getLinterConfigurationOptions() {

View file

@ -3,6 +3,7 @@
abstract class ArcanistXHPASTLinterRule extends Phobject {
private $linter = null;
private $lintID = null;
final public static function loadAllRules() {
$rules = array();
@ -31,6 +32,7 @@ abstract class ArcanistXHPASTLinterRule extends Phobject {
}
final public function getLintID() {
if ($this->lintID === null) {
$class = new ReflectionClass($this);
$const = $class->getConstant('ID');
@ -45,12 +47,16 @@ abstract class ArcanistXHPASTLinterRule extends Phobject {
if (!is_int($const)) {
throw new Exception(
pht(
'`%s` class `%s` has an invalid ID constant. ID must be an integer.',
'`%s` class `%s` has an invalid ID constant. '.
'ID must be an integer.',
__CLASS__,
get_class($this)));
}
return $const;
$this->lintID = $const;
}
return $this->lintID;
}
abstract public function getLintName();