Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: use direct find() instead of lookup all nodes then filter on BetterNodeFinder #3507

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,10 @@ public function findSameNamedExprs(Expr | Variable | Property | PropertyFetch |
return [];
}

$variables = $this->findInstancesOf($scopeNode, [Variable::class]);

return array_filter(
$variables,
fn (Variable $variable): bool => $this->nodeNameResolver->isName($variable, $exprName)
);
/** @var Variable[] $variables */
$variables = $this->find($scopeNode, fn (Node $node): bool =>
$node instanceof Variable && $this->nodeNameResolver->isName($node, $exprName));
return $variables;
}

if ($expr instanceof Property) {
Expand All @@ -399,13 +397,12 @@ public function findSameNamedExprs(Expr | Variable | Property | PropertyFetch |
return [];
}

$propertyFetches = $this->findInstancesOf($scopeNode, [PropertyFetch::class, StaticPropertyFetch::class]);
/** @var PropertyFetch[]|StaticPropertyFetch[] $propertyFetches */
$propertyFetches = $this->find($scopeNode, fn (Node $node): bool =>
($node instanceof PropertyFetch || $node instanceof StaticPropertyFetch)
&& $this->nodeNameResolver->isName($node->name, $exprName));

return array_filter(
$propertyFetches,
fn (PropertyFetch | StaticPropertyFetch $propertyFetch): bool =>
$this->nodeNameResolver->isName($propertyFetch->name, $exprName)
);
return $propertyFetches;
}

/**
Expand Down