diff --git a/src/Psalm/Codebase/Populator.php b/src/Psalm/Codebase/Populator.php index 49f3cfde9..df739804f 100644 --- a/src/Psalm/Codebase/Populator.php +++ b/src/Psalm/Codebase/Populator.php @@ -77,7 +77,7 @@ class Populator echo 'ClassLikeStorage is populating' . "\n"; } - foreach ($this->classlike_storage_provider->getAll() as $class_storage) { + foreach ($this->classlike_storage_provider->getNew() as $class_storage) { if (!$class_storage->user_defined && !$class_storage->stubbed) { continue; } @@ -93,14 +93,13 @@ class Populator echo 'FileStorage is populating' . "\n"; } - $all_file_storage = $this->file_storage_provider->getAll(); + $all_file_storage = $this->file_storage_provider->getNew(); foreach ($all_file_storage as $file_storage) { $this->populateFileStorage($file_storage); } - - foreach ($this->classlike_storage_provider->getAll() as $class_storage) { + foreach ($this->classlike_storage_provider->getNew() as $class_storage) { if ($this->config->allow_phpstorm_generics) { foreach ($class_storage->properties as $property_storage) { if ($property_storage->type) { @@ -182,6 +181,9 @@ class Populator if ($this->debug_output) { echo 'FileStorage is populated' . "\n"; } + + $this->classlike_storage_provider->populated(); + $this->file_storage_provider->populated(); } /** diff --git a/src/Psalm/Provider/ClassLikeStorageProvider.php b/src/Psalm/Provider/ClassLikeStorageProvider.php index 3dd1561b8..4e2c88912 100644 --- a/src/Psalm/Provider/ClassLikeStorageProvider.php +++ b/src/Psalm/Provider/ClassLikeStorageProvider.php @@ -12,6 +12,11 @@ class ClassLikeStorageProvider */ private static $storage = []; + /** + * @var array + */ + private static $new_storage = []; + /** * @var ?ClassLikeStorageCacheProvider */ @@ -69,9 +74,10 @@ class ClassLikeStorageProvider throw new \LogicException('Cannot exhume when there’s no cache'); } - self::$storage[$fq_classlike_name_lc] - = $cached_value - = $this->cache->getLatestFromCache($fq_classlike_name_lc, $file_path, $file_contents); + $cached_value = $this->cache->getLatestFromCache($fq_classlike_name_lc, $file_path, $file_contents); + + self::$storage[$fq_classlike_name_lc] = $cached_value; + self::$new_storage[$fq_classlike_name_lc] = $cached_value; return $cached_value; } @@ -84,12 +90,21 @@ class ClassLikeStorageProvider return self::$storage; } + /** + * @return array + */ + public function getNew() + { + return self::$new_storage; + } + /** * @param array $more * @return void */ public function addMore(array $more) { + self::$new_storage = array_merge($more, self::$new_storage); self::$storage = array_merge($more, self::$storage); } @@ -102,7 +117,9 @@ class ClassLikeStorageProvider { $fq_classlike_name_lc = strtolower($fq_classlike_name); - self::$storage[$fq_classlike_name_lc] = $storage = new ClassLikeStorage($fq_classlike_name); + $storage = new ClassLikeStorage($fq_classlike_name); + self::$storage[$fq_classlike_name_lc] = $storage; + self::$new_storage[$fq_classlike_name_lc] = $storage; return $storage; } @@ -124,4 +141,12 @@ class ClassLikeStorageProvider { self::$storage = []; } + + /** + * @return void + */ + public static function populated() + { + self::$new_storage = []; + } } diff --git a/src/Psalm/Provider/FileStorageProvider.php b/src/Psalm/Provider/FileStorageProvider.php index 4ac74dccc..ec99e31ae 100644 --- a/src/Psalm/Provider/FileStorageProvider.php +++ b/src/Psalm/Provider/FileStorageProvider.php @@ -13,6 +13,14 @@ class FileStorageProvider */ private static $storage = []; + /** + * A list of data useful to analyse new files + * Storing this statically is much faster (at least in PHP 7.2.1) + * + * @var array + */ + private static $new_storage = []; + /** * @var ?FileStorageCacheProvider */ @@ -74,6 +82,7 @@ class FileStorageProvider } self::$storage[$file_path] = $cached_value; + self::$new_storage[$file_path] = $cached_value; return true; } @@ -86,12 +95,21 @@ class FileStorageProvider return self::$storage; } + /** + * @return array + */ + public function getNew() + { + return self::$new_storage; + } + /** * @param array $more * @return void */ public function addMore(array $more) { + self::$new_storage = array_merge($more, self::$new_storage); self::$storage = array_merge($more, self::$storage); } @@ -104,7 +122,9 @@ class FileStorageProvider { $file_path_lc = strtolower($file_path); - self::$storage[$file_path_lc] = $storage = new FileStorage($file_path); + $storage = new FileStorage($file_path); + self::$storage[$file_path_lc] = $storage; + self::$new_storage[$file_path_lc] = $storage; return $storage; } @@ -116,4 +136,12 @@ class FileStorageProvider { self::$storage = []; } + + /** + * @return void + */ + public static function populated() + { + self::$new_storage = []; + } }