Skip to content

Commit 29fe3de

Browse files
makenowjustAry Borenszweig
authored and
Ary Borenszweig
committedJan 2, 2017
Avoid allocation in Iterator#with_index(&block)
1 parent 5739844 commit 29fe3de

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎src/iterator.cr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,10 @@ module Iterator(T)
10491049

10501050
# Yields each element in this iterator together with its index.
10511051
def with_index(offset : Int = 0)
1052-
with_index(offset).each do |value, index|
1052+
index = offset
1053+
each do |value|
10531054
yield value, index
1055+
index += 1
10541056
end
10551057
end
10561058

0 commit comments

Comments
 (0)
Please sign in to comment.