mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-29 02:02:40 +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:
parent
d54cb072fa
commit
bbccf1dd40
2 changed files with 42 additions and 19 deletions
|
@ -7,6 +7,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
|
|
||||||
private $rules = array();
|
private $rules = array();
|
||||||
|
|
||||||
|
private $lintNameMap;
|
||||||
|
private $lintSeverityMap;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->rules = ArcanistXHPASTLinterRule::loadAllRules();
|
$this->rules = ArcanistXHPASTLinterRule::loadAllRules();
|
||||||
}
|
}
|
||||||
|
@ -37,11 +40,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLintNameMap() {
|
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() {
|
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() {
|
public function getLinterConfigurationOptions() {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
abstract class ArcanistXHPASTLinterRule extends Phobject {
|
abstract class ArcanistXHPASTLinterRule extends Phobject {
|
||||||
|
|
||||||
private $linter = null;
|
private $linter = null;
|
||||||
|
private $lintID = null;
|
||||||
|
|
||||||
final public static function loadAllRules() {
|
final public static function loadAllRules() {
|
||||||
$rules = array();
|
$rules = array();
|
||||||
|
@ -31,26 +32,31 @@ abstract class ArcanistXHPASTLinterRule extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getLintID() {
|
final public function getLintID() {
|
||||||
$class = new ReflectionClass($this);
|
if ($this->lintID === null) {
|
||||||
|
$class = new ReflectionClass($this);
|
||||||
|
|
||||||
$const = $class->getConstant('ID');
|
$const = $class->getConstant('ID');
|
||||||
if ($const === false) {
|
if ($const === false) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht(
|
pht(
|
||||||
'`%s` class `%s` must define an ID constant.',
|
'`%s` class `%s` must define an ID constant.',
|
||||||
__CLASS__,
|
__CLASS__,
|
||||||
get_class($this)));
|
get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_int($const)) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'`%s` class `%s` has an invalid ID constant. '.
|
||||||
|
'ID must be an integer.',
|
||||||
|
__CLASS__,
|
||||||
|
get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->lintID = $const;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_int($const)) {
|
return $this->lintID;
|
||||||
throw new Exception(
|
|
||||||
pht(
|
|
||||||
'`%s` class `%s` has an invalid ID constant. ID must be an integer.',
|
|
||||||
__CLASS__,
|
|
||||||
get_class($this)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $const;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function getLintName();
|
abstract public function getLintName();
|
||||||
|
|
Loading…
Reference in a new issue