Skip to content

Commit

Permalink
Merge pull request #9466 from dwijnand/Iterator-addAll
Browse files Browse the repository at this point in the history
Give Iterator.newBuilder an efficient addAll
  • Loading branch information
dwijnand committed Feb 1, 2021
2 parents 7c736dc + 7b25684 commit 5b1d4f2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/library/scala/collection/Iterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ object Iterator extends IterableFactory[Iterator] {
*/
def newBuilder[A]: Builder[A, Iterator[A]] =
new ImmutableBuilder[A, Iterator[A]](empty[A]) {
override def addOne(elem: A): this.type = { elems = elems ++ single(elem); this }
override def addOne(elem: A): this.type = { elems ++= single(elem); this }
override def addAll(xs: IterableOnce[A]): this.type = { elems ++= xs.iterator; this }
}

/** Creates iterator that produces the results of some element computation a number of times.
Expand Down

0 comments on commit 5b1d4f2

Please sign in to comment.