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

Use loop-based DFS to resolve #341 (SystemStackError) #343

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/rspec/support/source/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ def location
@location ||= args.find { |arg| arg.is_a?(Location) }
end

def each(&block)
# We use a loop here (instead of recursion) to prevent SystemStackError
def each
return to_enum(__method__) unless block_given?

yield self
node_queue = []
node_queue << self

children.each do |child|
child.each(&block)
while (current_node = node_queue.shift)
yield current_node
node_queue.concat(current_node.children)
end
end

Expand Down