1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

Only repopulate the storage we care about

Big reduction on population time for single file edits
This commit is contained in:
Brown 2018-10-18 10:42:37 -04:00
parent a41c5c8a39
commit 2b6df3658c
3 changed files with 64 additions and 9 deletions

View File

@ -77,7 +77,7 @@ class Populator
echo 'ClassLikeStorage is populating' . "\n"; 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) { if (!$class_storage->user_defined && !$class_storage->stubbed) {
continue; continue;
} }
@ -93,14 +93,13 @@ class Populator
echo 'FileStorage is populating' . "\n"; 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) { foreach ($all_file_storage as $file_storage) {
$this->populateFileStorage($file_storage); $this->populateFileStorage($file_storage);
} }
foreach ($this->classlike_storage_provider->getNew() as $class_storage) {
foreach ($this->classlike_storage_provider->getAll() as $class_storage) {
if ($this->config->allow_phpstorm_generics) { if ($this->config->allow_phpstorm_generics) {
foreach ($class_storage->properties as $property_storage) { foreach ($class_storage->properties as $property_storage) {
if ($property_storage->type) { if ($property_storage->type) {
@ -182,6 +181,9 @@ class Populator
if ($this->debug_output) { if ($this->debug_output) {
echo 'FileStorage is populated' . "\n"; echo 'FileStorage is populated' . "\n";
} }
$this->classlike_storage_provider->populated();
$this->file_storage_provider->populated();
} }
/** /**

View File

@ -12,6 +12,11 @@ class ClassLikeStorageProvider
*/ */
private static $storage = []; private static $storage = [];
/**
* @var array<string, ClassLikeStorage>
*/
private static $new_storage = [];
/** /**
* @var ?ClassLikeStorageCacheProvider * @var ?ClassLikeStorageCacheProvider
*/ */
@ -69,9 +74,10 @@ class ClassLikeStorageProvider
throw new \LogicException('Cannot exhume when theres no cache'); throw new \LogicException('Cannot exhume when theres 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; return $cached_value;
} }
@ -84,12 +90,21 @@ class ClassLikeStorageProvider
return self::$storage; return self::$storage;
} }
/**
* @return array<string, ClassLikeStorage>
*/
public function getNew()
{
return self::$new_storage;
}
/** /**
* @param array<string, ClassLikeStorage> $more * @param array<string, ClassLikeStorage> $more
* @return void * @return void
*/ */
public function addMore(array $more) public function addMore(array $more)
{ {
self::$new_storage = array_merge($more, self::$new_storage);
self::$storage = array_merge($more, self::$storage); self::$storage = array_merge($more, self::$storage);
} }
@ -102,7 +117,9 @@ class ClassLikeStorageProvider
{ {
$fq_classlike_name_lc = strtolower($fq_classlike_name); $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; return $storage;
} }
@ -124,4 +141,12 @@ class ClassLikeStorageProvider
{ {
self::$storage = []; self::$storage = [];
} }
/**
* @return void
*/
public static function populated()
{
self::$new_storage = [];
}
} }

View File

@ -13,6 +13,14 @@ class FileStorageProvider
*/ */
private static $storage = []; 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<string, FileStorage>
*/
private static $new_storage = [];
/** /**
* @var ?FileStorageCacheProvider * @var ?FileStorageCacheProvider
*/ */
@ -74,6 +82,7 @@ class FileStorageProvider
} }
self::$storage[$file_path] = $cached_value; self::$storage[$file_path] = $cached_value;
self::$new_storage[$file_path] = $cached_value;
return true; return true;
} }
@ -86,12 +95,21 @@ class FileStorageProvider
return self::$storage; return self::$storage;
} }
/**
* @return array<string, FileStorage>
*/
public function getNew()
{
return self::$new_storage;
}
/** /**
* @param array<string, FileStorage> $more * @param array<string, FileStorage> $more
* @return void * @return void
*/ */
public function addMore(array $more) public function addMore(array $more)
{ {
self::$new_storage = array_merge($more, self::$new_storage);
self::$storage = array_merge($more, self::$storage); self::$storage = array_merge($more, self::$storage);
} }
@ -104,7 +122,9 @@ class FileStorageProvider
{ {
$file_path_lc = strtolower($file_path); $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; return $storage;
} }
@ -116,4 +136,12 @@ class FileStorageProvider
{ {
self::$storage = []; self::$storage = [];
} }
/**
* @return void
*/
public static function populated()
{
self::$new_storage = [];
}
} }