From 8088b4cdacf1691f8760470b4cb6caea6accf649 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 Mar 2012 12:20:46 -0800 Subject: [PATCH] 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 --- .../linter/xhpast/ArcanistXHPASTLinter.php | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php index 0674a058..c24db6e5 100644 --- a/src/lint/linter/xhpast/ArcanistXHPASTLinter.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinter.php @@ -164,6 +164,9 @@ final class ArcanistXHPASTLinter extends ArcanistLinter { $root = $this->trees[$path]->getRootNode(); + $root->buildSelectCache(); + $root->buildTokenCache(); + $this->lintUseOfThisInStaticMethods($root); $this->lintDynamicDefines($root); $this->lintSurpriseConstructors($root); @@ -406,19 +409,18 @@ final class ArcanistXHPASTLinter extends ArcanistLinter { protected function lintHashComments($root) { - $tokens = $root->getTokens(); - foreach ($tokens as $token) { - if ($token->getTypeName() == 'T_COMMENT') { - $value = $token->getValue(); - if ($value[0] == '#') { - $this->raiseLintAtOffset( - $token->getOffset(), - self::LINT_COMMENT_STYLE, - 'Use "//" single-line comments, not "#".', - '#', - '//'); - } + foreach ($root->selectTokensOfType('T_COMMENT') as $comment) { + $value = $comment->getValue(); + if ($value[0] != '#') { + continue; } + + $this->raiseLintAtOffset( + $comment->getOffset(), + self::LINT_COMMENT_STYLE, + 'Use "//" single-line comments, not "#".', + '#', + '//'); } } @@ -788,13 +790,12 @@ final class ArcanistXHPASTLinter extends ArcanistLinter { break; } } - foreach ($tokens as $token) { - if ($token->getTypeName() == 'T_CLOSE_TAG') { - $this->raiseLintAtToken( - $token, - self::LINT_PHP_CLOSE_TAG, - 'Do not use the PHP closing tag, "?>".'); - } + + foreach ($root->selectTokensOfType('T_CLOSE_TAG') as $token) { + $this->raiseLintAtToken( + $token, + self::LINT_PHP_CLOSE_TAG, + 'Do not use the PHP closing tag, "?>".'); } } @@ -1341,12 +1342,10 @@ final class ArcanistXHPASTLinter extends ArcanistLinter { } protected function lintTODOComments($root) { - $tokens = $root->getTokens(); - foreach ($tokens as $token) { - if (!$token->isComment()) { - continue; - } + $comments = $root->selectTokensOfType('T_COMMENT') + + $root->selectTokensOfType('T_DOC_COMMENT'); + foreach ($comments as $token) { $value = $token->getValue(); $matches = null; $preg = preg_match_all( -- 2.43.0