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

Improve performance of XHPASTLinter

Summary:
  - XHPASTLinter + coverage is ass-slow.
  - Use caching/perf options introduced by D1828.

Test Plan:
  - Ran profiling for unit tests with new --xprofile command line flag.
  - Old profile: https://secure.phabricator.com/xhprof/profile/PHID-FILE-uiuwsqa5wulj7eyfkjy2/
  - New profile: https://secure.phabricator.com/xhprof/profile/PHID-FILE-nl635t3jcp2sfo2spzwu/
  - Overall runtime decreased from 18.2s to 3.7s (4.9x performance increase) with coverage enabled.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1829
This commit is contained in:
epriestley 2012-03-08 12:20:46 -08:00
parent 92febf184e
commit 8088b4cdac

View file

@ -164,6 +164,9 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
$root = $this->trees[$path]->getRootNode(); $root = $this->trees[$path]->getRootNode();
$root->buildSelectCache();
$root->buildTokenCache();
$this->lintUseOfThisInStaticMethods($root); $this->lintUseOfThisInStaticMethods($root);
$this->lintDynamicDefines($root); $this->lintDynamicDefines($root);
$this->lintSurpriseConstructors($root); $this->lintSurpriseConstructors($root);
@ -406,21 +409,20 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
protected function lintHashComments($root) { protected function lintHashComments($root) {
$tokens = $root->getTokens(); foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
foreach ($tokens as $token) { $value = $comment->getValue();
if ($token->getTypeName() == 'T_COMMENT') { if ($value[0] != '#') {
$value = $token->getValue(); continue;
if ($value[0] == '#') { }
$this->raiseLintAtOffset( $this->raiseLintAtOffset(
$token->getOffset(), $comment->getOffset(),
self::LINT_COMMENT_STYLE, self::LINT_COMMENT_STYLE,
'Use "//" single-line comments, not "#".', 'Use "//" single-line comments, not "#".',
'#', '#',
'//'); '//');
} }
} }
}
}
/** /**
* Find cases where loops get nested inside each other but use the same * Find cases where loops get nested inside each other but use the same
@ -788,15 +790,14 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
break; break;
} }
} }
foreach ($tokens as $token) {
if ($token->getTypeName() == 'T_CLOSE_TAG') { foreach ($root->selectTokensOfType('T_CLOSE_TAG') as $token) {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$token, $token,
self::LINT_PHP_CLOSE_TAG, self::LINT_PHP_CLOSE_TAG,
'Do not use the PHP closing tag, "?>".'); 'Do not use the PHP closing tag, "?>".');
} }
} }
}
protected function lintNamingConventions($root) { protected function lintNamingConventions($root) {
@ -1341,12 +1342,10 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
} }
protected function lintTODOComments($root) { protected function lintTODOComments($root) {
$tokens = $root->getTokens(); $comments = $root->selectTokensOfType('T_COMMENT') +
foreach ($tokens as $token) { $root->selectTokensOfType('T_DOC_COMMENT');
if (!$token->isComment()) {
continue;
}
foreach ($comments as $token) {
$value = $token->getValue(); $value = $token->getValue();
$matches = null; $matches = null;
$preg = preg_match_all( $preg = preg_match_all(