Skip to content

Commit 45a50f4

Browse files
committed
fixup! [perf] [experiment] preload all node classes once at start
1 parent 8b775d2 commit 45a50f4

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

scripts/src/Finder/NodeClassFinder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public static function find(): array
3030

3131
$instantiableNodeClasses = array_filter($nodeClasses, function (string $nodeClass): bool {
3232
$nodeClassReflection = new ReflectionClass($nodeClass);
33-
if ($nodeClassReflection->isAbstract()) {
34-
return false;
35-
}
33+
if ($nodeClassReflection->isAbstract()) {
34+
return false;
35+
}
3636

37-
return ! $nodeClassReflection->isInterface();
37+
return ! $nodeClassReflection->isInterface();
3838
});
3939

4040
return $instantiableNodeClasses;

src/PhpParser/NodeTraverser/RectorNodeTraverser.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,28 @@ public function getVisitorsForNode(Node $node): array
6868
Assert::true($this->areNodeVisitorsPrepared);
6969

7070
return $this->visitorsPerNodeClass[$node::class] ?? [];
71-
//
72-
// $nodeClass = $node::class;
73-
//
74-
// static $isACheckCounter = 0;
75-
//
76-
// if (! isset($this->visitorsPerNodeClass[$nodeClass])) {
77-
// $this->visitorsPerNodeClass[$nodeClass] = [];
78-
// /** @var RectorInterface $visitor */
79-
// foreach ($this->visitors as $visitor) {
80-
// foreach ($visitor->getNodeTypes() as $nodeType) {
81-
// if (is_a($nodeClass, $nodeType, true)) {
82-
// ++$isACheckCounter;
83-
//
84-
// $this->visitorsPerNodeClass[$nodeClass][] = $visitor;
85-
// continue 2;
86-
// }
87-
// }
88-
// }
89-
//
90-
// dump($isACheckCounter);
91-
// }
92-
// return $this->visitorsPerNodeClass[$nodeClass];
71+
//
72+
// $nodeClass = $node::class;
73+
//
74+
// static $isACheckCounter = 0;
75+
//
76+
// if (! isset($this->visitorsPerNodeClass[$nodeClass])) {
77+
// $this->visitorsPerNodeClass[$nodeClass] = [];
78+
// /** @var RectorInterface $visitor */
79+
// foreach ($this->visitors as $visitor) {
80+
// foreach ($visitor->getNodeTypes() as $nodeType) {
81+
// if (is_a($nodeClass, $nodeType, true)) {
82+
// ++$isACheckCounter;
83+
//
84+
// $this->visitorsPerNodeClass[$nodeClass][] = $visitor;
85+
// continue 2;
86+
// }
87+
// }
88+
// }
89+
//
90+
// dump($isACheckCounter);
91+
// }
92+
// return $this->visitorsPerNodeClass[$nodeClass];
9393
}
9494

9595
/**
@@ -117,7 +117,7 @@ private function prepareNodeVisitors(): void
117117
foreach ($this->visitors as $visitor) {
118118
foreach ($visitor->getNodeTypes() as $matchingNodeType) {
119119
if (is_a($nodeClass, $matchingNodeType, true)) {
120-
$this->visitorsPerNodeClass[$nodeClass][] = $visitor;
120+
$this->visitorsPerNodeClass[$nodeClass][] = $visitor;
121121

122122
++$counter;
123123
}

0 commit comments

Comments
 (0)