Skip to content

Commit 2b662f4

Browse files
authored
Merge pull request scala#6887 from isaacl/iterableLen
IterableOnce.copyToArray micro opt
2 parents fbfe3f8 + 60ee72a commit 2b662f4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/library/scala/collection/IterableOnce.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,10 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
643643
* $willNotTerminateInf
644644
*/
645645
def copyToArray[B >: A](xs: Array[B], start: Int = 0): xs.type = {
646+
val xsLen = xs.length
646647
val it = iterator
647648
var i = start
648-
while (i < xs.length && it.hasNext) {
649+
while (i < xsLen && it.hasNext) {
649650
xs(i) = it.next()
650651
i += 1
651652
}

0 commit comments

Comments
 (0)