Skip to content

Commit

Permalink
[NodeDecorator] Improve MixPhpHtmlDecorator::decorateNextNodesInlineH…
Browse files Browse the repository at this point in the history
…TML() performance: stop loop on found InlineHTML (#3305)

* [NodeDecorator] Improve MixPhpHtmlDecorator performance: stop on found InlineHTML

* update fixture

* stop on isset old token exists
  • Loading branch information
samsonasik committed Jan 25, 2023
1 parent 828ec4e commit fe326cb
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/NodeDecorator/MixPhpHtmlDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function decorateNextNodesInlineHTML(File $file, array $nodes): void

$endTokenPost = $subNode->getEndTokenPos();
if (isset($oldTokens[$endTokenPost])) {
continue;
return;
}

if (! isset($nodes[$key + 1])) {
Expand All @@ -51,6 +51,7 @@ public function decorateNextNodesInlineHTML(File $file, array $nodes): void
if ($nodes[$key + 1] instanceof InlineHTML) {
// No token end? Just added
$nodes[$key + 1]->setAttribute(AttributeKey::ORIGINAL_NODE, null);
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----
<?php

echo 'this is new stmt before InlineHTML';
echo 'this is new stmt before InlineHTML';
?>
<div><?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Echo_;
use PhpParser\Node\Stmt\InlineHTML;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -36,7 +37,7 @@ public function refactor(Node $node)
$echo = new Echo_([new String_('this is new stmt before InlineHTML')]);

$node->stmts = array_merge(
[$echo],
[$echo, $echo],
$node->stmts
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----
<?php

echo 'this is new stmt before InlineHTML';
echo 'this is new stmt before InlineHTML';
?>
<div><?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ echo $this->filter ;
-----
<?php

echo 'this is new stmt before InlineHTML';
echo 'this is new stmt before InlineHTML';
?>
<div><?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function refactor(Node $node)
$this->justAdded[$this->file->getFilePath()] = true;

return [
$echo,
$echo,
$node,
];
Expand Down

0 comments on commit fe326cb

Please sign in to comment.