From 731baeb619c884b4f9716a3a67dba3e3d8ac8403 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 23 Apr 2023 00:07:19 +0200 Subject: [PATCH] Improve NodeComparator performance (#3659) --- src/PhpParser/Comparing/NodeComparator.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/PhpParser/Comparing/NodeComparator.php b/src/PhpParser/Comparing/NodeComparator.php index 0a9edd8a93a..fd568b4994b 100644 --- a/src/PhpParser/Comparing/NodeComparator.php +++ b/src/PhpParser/Comparing/NodeComparator.php @@ -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);