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

Commit

Permalink
Use loop-based DFS to resolve #341 (SystemStackError)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigjbass authored and myronmarston committed Jan 30, 2018
1 parent 43d0e16 commit b5be67a
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit b5be67a

Please sign in to comment.