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

Commit

Permalink
Merge pull request #343 from craigjbass/use-loop-based-depth-first-se…
Browse files Browse the repository at this point in the history
…arch

Use loop-based DFS to resolve #341 (SystemStackError)
  • Loading branch information
myronmarston authored Jan 30, 2018
2 parents 2f9091b + bbb2c88 commit 492e223
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 492e223

Please sign in to comment.