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,19 +409,18 @@ 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(
$token->getOffset(),
self::LINT_COMMENT_STYLE,
'Use "//" single-line comments, not "#".',
'#',
'//');
}
} }
$this->raiseLintAtOffset(
$comment->getOffset(),
self::LINT_COMMENT_STYLE,
'Use "//" single-line comments, not "#".',
'#',
'//');
} }
} }
@ -788,13 +790,12 @@ 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, "?>".');
}
} }
} }
@ -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(