Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,12 @@ public function getScopeNativeType(Expr $expr): Type

private function getNodeKey(Expr $node): string
{
$key = $this->exprPrinter->printExpr($node);
// perf optimize for the most common path
if ($node instanceof Variable && !$node->name instanceof Expr) {
return '$' . $node->name;
}
Comment on lines +920 to +923
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I duplicated the logic to here now, as getNodeKey is by far the most common caller of exprPrinter->printExpr:

grafik

and with this check here, we also prevent unnecessary getAttributes calls below


$key = $this->exprPrinter->printExpr($node);
$attributes = $node->getAttributes();
if (
$node instanceof Node\FunctionLike
Expand Down
5 changes: 5 additions & 0 deletions src/Node/Printer/ExprPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function __construct(private Printer $printer)

public function printExpr(Expr $expr): string
{
// perf optimize for the most common path
if ($expr instanceof Expr\Variable && !$expr->name instanceof Expr) {
return '$' . $expr->name;
}

/** @var string|null $exprString */
$exprString = $expr->getAttribute(self::ATTRIBUTE_CACHE_KEY);
if ($exprString === null) {
Expand Down
Loading