1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Merge pull request #8054 from kkmuffme/runtime-cache-origin-location

store origin location by ID to speed up psalm by up to 75%
This commit is contained in:
orklah 2022-06-04 18:47:14 +02:00 committed by GitHub
commit f47b4180fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,9 @@ class VariableUseGraph extends DataFlowGraph
/** @var array<string, DataFlowNode> */ /** @var array<string, DataFlowNode> */
private $nodes = []; private $nodes = [];
/** @var array<string, list<CodeLocation>> */
private $origin_locations_by_id = [];
public function addNode(DataFlowNode $node): void public function addNode(DataFlowNode $node): void
{ {
$this->nodes[$node->id] = $node; $this->nodes[$node->id] = $node;
@ -94,6 +97,10 @@ class VariableUseGraph extends DataFlowGraph
*/ */
public function getOriginLocations(DataFlowNode $assignment_node): array public function getOriginLocations(DataFlowNode $assignment_node): array
{ {
if (isset($this->origin_locations_by_id[$assignment_node->id])) {
return $this->origin_locations_by_id[$assignment_node->id];
}
$visited_child_ids = []; $visited_child_ids = [];
$origin_locations = []; $origin_locations = [];
@ -128,6 +135,8 @@ class VariableUseGraph extends DataFlowGraph
$child_nodes = $new_parent_nodes; $child_nodes = $new_parent_nodes;
} }
$this->origin_locations_by_id[$assignment_node->id] = $origin_locations;
return $origin_locations; return $origin_locations;
} }