Skip to content

Commit a98a1e0

Browse files
staabmondrejmirtes
authored andcommitted
NodeScopeResolver: cheap checks first
1 parent 7e2be85 commit a98a1e0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,13 +946,13 @@ private function processStmtNode(
946946
$currentScope = $scope;
947947
$result = $this->processExprNode($stmt, $stmt->expr, $scope, $storage, static function (Node $node, Scope $scope) use ($nodeCallback, $currentScope, &$hasAssign): void {
948948
$nodeCallback($node, $scope);
949-
if ($scope->getAnonymousFunctionReflection() !== $currentScope->getAnonymousFunctionReflection()) {
949+
if (!$node instanceof VariableAssignNode && !$node instanceof PropertyAssignNode) {
950950
return;
951951
}
952-
if ($scope->getFunction() !== $currentScope->getFunction()) {
952+
if ($scope->getAnonymousFunctionReflection() !== $currentScope->getAnonymousFunctionReflection()) {
953953
return;
954954
}
955-
if (!$node instanceof VariableAssignNode && !$node instanceof PropertyAssignNode) {
955+
if ($scope->getFunction() !== $currentScope->getFunction()) {
956956
return;
957957
}
958958

@@ -1272,8 +1272,9 @@ private function processStmtNode(
12721272
}
12731273

12741274
$originalStorage = $storage;
1275-
$storage = $originalStorage->duplicate();
12761275
if ($context->isTopLevel()) {
1276+
$storage = $originalStorage->duplicate();
1277+
12771278
$originalScope = $this->polluteScopeWithAlwaysIterableForeach ? $scope->filterByTruthyValue($arrayComparisonExpr) : $scope;
12781279
$bodyScope = $this->enterForeach($originalScope, $storage, $originalScope, $stmt, $nodeCallback);
12791280
$count = 0;
@@ -1337,9 +1338,9 @@ private function processStmtNode(
13371338
&& count($scopesWithIterableValueType) > 0
13381339
&& !$continueExitPointHasUnoriginalKeyType
13391340
&& $stmt->keyVar !== null
1341+
&& (!$hasExpr->no() || !$stmt->expr instanceof Variable)
13401342
&& $exprType->isArray()->yes()
13411343
&& $exprType->isConstantArray()->no()
1342-
&& (!$hasExpr->no() || !$stmt->expr instanceof Variable)
13431344
) {
13441345
$arrayExprDimFetch = new ArrayDimFetch($stmt->expr, $stmt->keyVar);
13451346
$arrayDimFetchLoopTypes = [];
@@ -1398,7 +1399,7 @@ private function processStmtNode(
13981399
}
13991400

14001401
$isIterableAtLeastOnce = $exprType->isIterableAtLeastOnce();
1401-
if ($exprType->isIterable()->no() || $isIterableAtLeastOnce->maybe()) {
1402+
if ($isIterableAtLeastOnce->maybe() || $exprType->isIterable()->no()) {
14021403
$finalScope = $finalScope->mergeWith($scope->filterByTruthyValue(new BooleanOr(
14031404
new BinaryOp\Identical(
14041405
$stmt->expr,

0 commit comments

Comments
 (0)