Avoid by-reference iteration in NodeTraverser

No need to create reference wrappers around every element in the
array.
This commit is contained in:
Nikita Popov 2023-09-26 20:25:37 +02:00
parent b4183c2b09
commit de84f76766

View File

@ -175,7 +175,7 @@ class NodeTraverser implements NodeTraverserInterface {
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;
@ -185,7 +185,7 @@ class NodeTraverser implements NodeTraverserInterface {
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;
@ -225,7 +225,7 @@ class NodeTraverser implements NodeTraverserInterface {
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;