Skip to content

Commit

Permalink
Optimise IndexedSeq.foldRight to use reverseIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed May 7, 2020
1 parent 969bc1d commit 6150705
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/library/scala/collection/IndexedSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ trait IndexedSeqOps[+A, +CC[_], +C] extends Any with SeqOps[A, CC, C] { self =>
} else Iterator.empty.next()
}

override def foldRight[B](z: B)(f: (A, B) => B): B = {
val it = reverseIterator
var b = z
while (it.hasNext)
b = f(it.next(), b)
b
}

override def view: IndexedSeqView[A] = new IndexedSeqView.Id[A](this)

@deprecated("Use .view.slice(from, until) instead of .view(from, until)", "2.13.0")
Expand Down

0 comments on commit 6150705

Please sign in to comment.