From 59438d0647995f75bd1bf7159a248340d3708abd Mon Sep 17 00:00:00 2001 From: Erik Erlandson Date: Thu, 4 Sep 2014 11:10:13 -0700 Subject: SI-8835 Fix implementation of Iterator drop to remove quadratic behavior --- src/library/scala/collection/Iterator.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/library') diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 660cc5a42a..0115cc154c 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -320,7 +320,14 @@ trait Iterator[+A] extends TraversableOnce[A] { * it omits the first `n` values. * @note Reuse: $consumesAndProducesIterator */ - def drop(n: Int): Iterator[A] = slice(n, Int.MaxValue) + def drop(n: Int): Iterator[A] = { + var j = 0 + while (j < n && this.hasNext) { + this.next + j += 1 + } + this + } /** Creates an iterator returning an interval of the values produced by this iterator. * -- cgit v1.2.3