Skip to content

Commit

Permalink
Don't use Enumerator#count for lazy enums.
Browse files Browse the repository at this point in the history
This causes methods such as Enumerable#enumerator_size to go into a (near)
infinite loop depending on the size of the lazy enumerator.
  • Loading branch information
Yorick Peterse committed Feb 17, 2015
1 parent 76a23a6 commit 07a4c4b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kernel/common/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def size
@size.call
elsif @size
@size
else
# Lazy enums don't have a size and in case of Rbx can go into an infinite
# loop when using "count".
elsif !kind_of?(Enumerator::Lazy)
count
end
end
Expand Down

0 comments on commit 07a4c4b

Please sign in to comment.