Skip to content

Commit c003048

Browse files
authored
create less objects for zipWithIndex (scala/scala#8685)
create less objects for zipWithIndex
2 parents e7e63cb + 03b3c2e commit c003048

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/src/scala/collection/IterableLike.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ self =>
282282

283283
def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Repr, (A1, Int), That]): That = {
284284
val b = bf(repr)
285+
val these = this.iterator
285286
var i = 0
286-
for (x <- this) {
287-
b += ((x, i))
287+
while (these.hasNext) {
288+
b += ((these.next(), i))
288289
i += 1
289290
}
290291
b.result()

0 commit comments

Comments
 (0)