Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 6c64ad2

Browse files
committed
Use loop-based DFS to resolve #341 (SystemStackError)
1 parent 2f9091b commit 6c64ad2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/rspec/support/source/node.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ def location
4545
@location ||= args.find { |arg| arg.is_a?(Location) }
4646
end
4747

48-
def each(&block)
48+
def each
4949
return to_enum(__method__) unless block_given?
5050

51-
yield self
51+
outstanding_nodes = []
52+
outstanding_nodes << self
53+
while outstanding_nodes.length > 0
54+
current_node = outstanding_nodes.pop
55+
current_node.children.each do |node|
56+
outstanding_nodes.unshift(node)
57+
end
5258

53-
children.each do |child|
54-
child.each(&block)
59+
yield current_node
5560
end
5661
end
5762

0 commit comments

Comments
 (0)