Skip to content

Commit

Permalink
Avoid allocation in Iterator#with_index(&block)
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and asterite committed Jan 2, 2017
1 parent 5739844 commit 29fe3de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/iterator.cr
Expand Up @@ -1049,8 +1049,10 @@ module Iterator(T)

# Yields each element in this iterator together with its index.
def with_index(offset : Int = 0)
with_index(offset).each do |value, index|
index = offset
each do |value|
yield value, index
index += 1
end
end

Expand Down

0 comments on commit 29fe3de

Please sign in to comment.