From 3408a97088d6af676114814fa83455b11ac4da76 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Dec 2022 22:10:00 +0100 Subject: [PATCH] Faster Scope->shouldInvalidateExpression() --- src/Analyser/MutatingScope.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 4997ff65e7..79178a0cb2 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -3500,6 +3500,11 @@ private function shouldInvalidateExpression(string $exprStringToInvalidate, Expr return false; } + // Variables will not contain traversable expressions. skip the NodeFinder overhead + if ($expr instanceof Variable && is_string($expr->name)) { + return $exprStringToInvalidate === $this->getNodeKey($expr); + } + $nodeFinder = new NodeFinder(); $expressionToInvalidateClass = get_class($exprToInvalidate); $found = $nodeFinder->findFirst([$expr], function (Node $node) use ($expressionToInvalidateClass, $exprStringToInvalidate): bool {