Skip to content

Commit

Permalink
[Performance] Remove loop $newStmts on BetterNodeFinder (#3889)
Browse files Browse the repository at this point in the history
* [Performance] Remove loop $newStmts on BetterNodeFinder

* clean up
  • Loading branch information
samsonasik committed May 18, 2023
1 parent 24f8610 commit cee58fb
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/PhpParser/Node/BetterNodeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,22 +637,9 @@ private function resolveNodeFromFile(array $newStmts, Node $node, bool $isPrevio
}

$currentStmtKey = $node->getAttribute(AttributeKey::STMT_KEY);
foreach ($newStmts as $key => $newStmt) {
$stmtKey = $newStmt->getAttribute(AttributeKey::STMT_KEY);
if ($stmtKey !== $currentStmtKey) {
continue;
}

if ($key !== $currentStmtKey) {
continue;
}

return $isPrevious
? ($newStmts[$key - 1] ?? null)
: ($newStmts[$key + 1] ?? null);
}
$stmtKey = $isPrevious ? $currentStmtKey - 1 : $currentStmtKey + 1;

return null;
return $newStmts[$stmtKey] ?? null;
}

/**
Expand Down

0 comments on commit cee58fb

Please sign in to comment.