Skip to content
Permalink
Browse files

Speed up accessing node data

Ref #1837
  • Loading branch information
muglug committed Nov 26, 2019
1 parent f97a8f0 commit 90cb3f4472cc5f903160c7d7828da96357b4f11a
Showing with 31 additions and 75 deletions.
  1. +1 −2 composer.json
  2. +0 −1 psalm.xml.dist
  3. +30 −20 src/Psalm/Internal/Provider/NodeDataProvider.php
  4. +0 −52 src/spl_object_id.php
@@ -32,8 +32,7 @@
"Psalm\\": "src/Psalm"
},
"files": [
"src/functions.php",
"src/spl_object_id.php"
"src/functions.php"
]
},
"autoload-dev": {
@@ -23,7 +23,6 @@
<file name="src/Psalm/Internal/CallMap.php"/>
<file name="src/Psalm/Internal/Traverser/CustomTraverser.php"/>
<file name="tests/ErrorBaselineTest.php"/>
<file name="src/spl_object_id.php"/>
<file name="vendor/symfony/console/Command/Command.php"/>
<directory name="src/Psalm/Internal/Stubs"/>
<directory name="tests/fixtures"/>
@@ -3,40 +3,52 @@
namespace Psalm\Internal\Provider;
use PhpParser;
use function spl_object_id;
use SplObjectStorage;
use Psalm\Type\Union;
class NodeDataProvider implements \Psalm\NodeTypeProvider
{
/** @var array<int, Union> */
private $node_types = [];
/** @var SplObjectStorage<PhpParser\Node, Union> */
private $node_types;
/** @var array<int, array<string, non-empty-list<non-empty-list<string>>>|null> */
private $node_assertions = [];
/** @var SplObjectStorage<PhpParser\Node, array<string, non-empty-list<non-empty-list<string>>>|null> */
private $node_assertions;
/** @var array<int, array<int, \Psalm\Storage\Assertion>> */
private $node_if_true_assertions = [];
/** @var SplObjectStorage<PhpParser\Node, array<int, \Psalm\Storage\Assertion>> */
private $node_if_true_assertions;
/** @var array<int, array<int, \Psalm\Storage\Assertion>> */
private $node_if_false_assertions = [];
/** @var SplObjectStorage<PhpParser\Node, array<int, \Psalm\Storage\Assertion>> */
private $node_if_false_assertions;
/** @var bool */
public $cache_assertions = true;
public function __construct()
{
/** @psalm-suppress PropertyTypeCoercion */
$this->node_types = new SplObjectStorage();
/** @psalm-suppress PropertyTypeCoercion */
$this->node_assertions = new SplObjectStorage();
/** @psalm-suppress PropertyTypeCoercion */
$this->node_if_true_assertions = new SplObjectStorage();
/** @psalm-suppress PropertyTypeCoercion */
$this->node_if_false_assertions = new SplObjectStorage();
}
/**
* @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node
*/
public function setType($node, Union $type) : void
{
$this->node_types[spl_object_id($node)] = $type;
$this->node_types[$node] = $type;
}
/**
* @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node
*/
public function getType($node) : ?Union
{
return $this->node_types[spl_object_id($node)] ?? null;
return $this->node_types[$node] ?? null;
}
/**
@@ -49,7 +61,7 @@ public function setAssertions($node, ?array $assertions) : void
return;
}
$this->node_assertions[spl_object_id($node)] = $assertions;
$this->node_assertions[$node] = $assertions;
}
/**
@@ -62,7 +74,7 @@ public function getAssertions($node) : ?array
return null;
}
return $this->node_assertions[spl_object_id($node)] ?? null;
return $this->node_assertions[$node] ?? null;
}
/**
@@ -71,7 +83,7 @@ public function getAssertions($node) : ?array
*/
public function setIfTrueAssertions($node, array $assertions) : void
{
$this->node_if_true_assertions[spl_object_id($node)] = $assertions;
$this->node_if_true_assertions[$node] = $assertions;
}
/**
@@ -80,7 +92,7 @@ public function setIfTrueAssertions($node, array $assertions) : void
*/
public function getIfTrueAssertions($node) : ?array
{
return $this->node_if_true_assertions[spl_object_id($node)] ?? null;
return $this->node_if_true_assertions[$node] ?? null;
}
/**
@@ -89,7 +101,7 @@ public function getIfTrueAssertions($node) : ?array
*/
public function setIfFalseAssertions($node, array $assertions) : void
{
$this->node_if_false_assertions[spl_object_id($node)] = $assertions;
$this->node_if_false_assertions[$node] = $assertions;
}
/**
@@ -98,7 +110,7 @@ public function setIfFalseAssertions($node, array $assertions) : void
*/
public function getIfFalseAssertions($node) : ?array
{
return $this->node_if_false_assertions[spl_object_id($node)] ?? null;
return $this->node_if_false_assertions[$node] ?? null;
}
/**
@@ -116,8 +128,6 @@ public function isPureCompatible($node) : bool
*/
public function clearNodeOfTypeAndAssertions($node) : void
{
$id = spl_object_id($node);
unset($this->node_types[$id], $this->node_assertions[$id]);
unset($this->node_types[$node], $this->node_assertions[$node]);
}
}

This file was deleted.

0 comments on commit 90cb3f4

Please sign in to comment.
You can’t perform that action at this time.