Skip to content

Commit

Permalink
Avoid by-reference iteration in NodeTraverser
Browse files Browse the repository at this point in the history
No need to create reference wrappers around every element in the
array.
  • Loading branch information
nikic committed Sep 26, 2023
1 parent b4183c2 commit de84f76
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/PhpParser/NodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function traverseNode(Node $node): void {
protected function traverseArray(array $nodes): array {
$doNodes = [];

foreach ($nodes as $i => &$node) {
foreach ($nodes as $i => $node) {
if ($node instanceof Node) {
$traverseChildren = true;
$visitorIndex = -1;
Expand All @@ -185,7 +185,7 @@ protected function traverseArray(array $nodes): array {
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($node, $return);
$node = $return;
$nodes[$i] = $node = $return;
} elseif (\is_array($return)) {
$doNodes[] = [$i, $return];
continue 2;
Expand Down Expand Up @@ -225,7 +225,7 @@ protected function traverseArray(array $nodes): array {
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($node, $return);
$node = $return;
$nodes[$i] = $node = $return;
} elseif (\is_array($return)) {
$doNodes[] = [$i, $return];
break;
Expand Down

0 comments on commit de84f76

Please sign in to comment.