Skip to content

Commit

Permalink
Optimize IndexedSeqOptimized.toList
Browse files Browse the repository at this point in the history
Notably, this will be used in `List(a, b, c)`.
  • Loading branch information
retronym committed Dec 6, 2017
1 parent a455861 commit 84890f3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/library/scala/collection/IndexedSeqOptimized.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,15 @@ trait IndexedSeqOptimized[+A, +Repr] extends Any with IndexedSeqLike[A, Repr] {
case _ =>
super.endsWith(that)
}

override def toList: List[A] = {
var i = length - 1
var result: List[A] = Nil
while (i >= 0) {
result ::= apply(i)
i -= 1
}
result
}
}

0 comments on commit 84890f3

Please sign in to comment.