From 38ea2e7f96f9781f9de1d11b6d9970feae3eac32 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 17 Aug 2021 15:02:34 -0600 Subject: [PATCH] Address Ameba issue --- src/spectator/node_iterator.cr | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/spectator/node_iterator.cr b/src/spectator/node_iterator.cr index 48610a7..0dbc2bb 100644 --- a/src/spectator/node_iterator.cr +++ b/src/spectator/node_iterator.cr @@ -18,25 +18,20 @@ module Spectator # Retrieves the next `Node`. # If there are none left, then `Iterator::Stop` is returned. def next - # Keep going until either: - # a. a node is found. - # b. the stack is empty. - until @stack.empty? - # Retrieve the next node. - node = @stack.pop + # Nothing left to iterate. + return stop if @stack.empty? - # If the node is a group, add its direct children to the queue - # in reverse order so that the tree is traversed in pre-order. - if node.is_a?(Indexable(Node)) - node.reverse_each { |child| @stack.push(child) } - end + # Retrieve the next node. + node = @stack.pop - # Return the current node. - return node + # If the node is a group, add its direct children to the queue + # in reverse order so that the tree is traversed in pre-order. + if node.is_a?(Indexable(Node)) + node.reverse_each { |child| @stack.push(child) } end - # Nothing left to iterate. - stop + # Return the current node. + node end # Restart the iterator at the beginning.