From 46ce8a5a35f9057b30151b5cb99a80642d913d22 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Mon, 27 Apr 2015 23:20:31 +1000 Subject: [PATCH] Memoize paths Summary: Ref T7892. Memoize paths returned from `ARcanistLinter::getPaths()` to improve runtime performance. Test Plan: Wiped ~0.5 seconds off the total time to lint rARC. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7892 Differential Revision: https://secure.phabricator.com/D12520 --- src/lint/linter/ArcanistLinter.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lint/linter/ArcanistLinter.php b/src/lint/linter/ArcanistLinter.php index d778e161..23a7f7a6 100644 --- a/src/lint/linter/ArcanistLinter.php +++ b/src/lint/linter/ArcanistLinter.php @@ -16,8 +16,9 @@ abstract class ArcanistLinter { const GRANULARITY_GLOBAL = 4; private $id; - protected $paths = array(); - protected $data = array(); + protected $paths = array(); + private $filteredPaths = null; + protected $data = array(); protected $engine; protected $activePath; protected $messages = array(); @@ -274,19 +275,24 @@ abstract class ArcanistLinter { final public function addPath($path) { $this->paths[$path] = $path; + $this->filteredPaths = null; return $this; } final public function setPaths(array $paths) { $this->paths = $paths; + $this->filteredPaths = null; return $this; } /** * Filter out paths which this linter doesn't act on (for example, because * they are binaries and the linter doesn't apply to binaries). + * + * @param list + * @return list */ - final private function filterPaths($paths) { + final private function filterPaths(array $paths) { $engine = $this->getEngine(); $keep = array(); @@ -314,7 +320,11 @@ abstract class ArcanistLinter { } final public function getPaths() { - return $this->filterPaths(array_values($this->paths)); + if ($this->filteredPaths === null) { + $this->filteredPaths = $this->filterPaths(array_values($this->paths)); + } + + return $this->filteredPaths; } final public function addData($path, $data) {