Skip to content

Commit 0e48ba4

Browse files
committed
Optimize IndexedSeqOptimized.toList
Notably, this will be used in `List(a, b, c)`.
1 parent c32125b commit 0e48ba4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/src/scala/collection/IndexedSeqOptimized.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,15 @@ trait IndexedSeqOptimized[+A, +Repr] extends Any with IndexedSeqLike[A, Repr] {
276276
case _ =>
277277
super.endsWith(that)
278278
}
279+
280+
override def toList: List[A] = {
281+
var i = length - 1
282+
var result: List[A] = Nil
283+
while (i >= 0) {
284+
result ::= apply(i)
285+
i -= 1
286+
}
287+
result
288+
}
279289
}
280290

0 commit comments

Comments
 (0)