Skip to content

Commit

Permalink
Improve NodeComparator performance (#3659)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 22, 2023
1 parent 81e7980 commit 731baeb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/PhpParser/Comparing/NodeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,27 @@ public function printWithoutComments(Node | array | null $node): string
*/
public function areNodesEqual(Node | array | null $firstNode, Node | array | null $secondNode): bool
{
if ($firstNode instanceof Node && $secondNode === null) {
if ($firstNode instanceof Node && !$secondNode instanceof Node) {
return false;
}

if ($secondNode instanceof Node && $firstNode === null) {
if (!$firstNode instanceof Node && $secondNode instanceof Node) {
return false;
}

if (is_array($firstNode)) {
Assert::allIsAOf($firstNode, Node::class);

if ($secondNode === null) {
if (!is_array($secondNode)) {
return false;
}

Assert::allIsAOf($firstNode, Node::class);
}

if (is_array($secondNode)) {
Assert::allIsAOf($secondNode, Node::class);

if ($firstNode === null) {
if (!is_array($firstNode)) {
return false;
}

Assert::allIsAOf($secondNode, Node::class);
}

return $this->printWithoutComments($firstNode) === $this->printWithoutComments($secondNode);
Expand Down

0 comments on commit 731baeb

Please sign in to comment.