File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -191,14 +191,19 @@ final public function enterNode(Node $node): int|Node|null
191191
192192 /**
193193 * Replacing nodes in leaveNode() method avoids infinite recursion
194- * see"infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown
194+ * see "infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown
195195 */
196196 final public function leaveNode (Node $ node ): array |int |Node |null
197197 {
198198 if ($ node ->hasAttribute (AttributeKey::ORIGINAL_NODE )) {
199199 return null ;
200200 }
201201
202+ // perf: hash node only if there is some object to be removed or replaced by array
203+ if ($ this ->toBeRemovedNodeId === null && $ this ->nodesToReturn === []) {
204+ return null ;
205+ }
206+
202207 $ objectId = spl_object_id ($ node );
203208 if ($ this ->toBeRemovedNodeId === $ objectId ) {
204209 $ this ->toBeRemovedNodeId = null ;
You can’t perform that action at this time.
0 commit comments