diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-20 18:09:08 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-20 18:09:08 +0000 |
commit | e78864041f80ae25ba0c8d281188068cd1355a98 (patch) | |
tree | 3ebd22e9977b2d372330e4e9b11378e76983ea21 /src/library | |
parent | 4c9372f665660324023ae49edb42ac1e70ed7e79 (diff) | |
download | scala-e78864041f80ae25ba0c8d281188068cd1355a98.tar.gz scala-e78864041f80ae25ba0c8d281188068cd1355a98.tar.bz2 scala-e78864041f80ae25ba0c8d281188068cd1355a98.zip |
Tweak to Iterator.++ to keep it from going into...
Tweak to Iterator.++ to keep it from going into an infinite loop on x ++
x.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 20573ca3ab..751d084770 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -316,10 +316,17 @@ trait Iterator[+A] { self => /** Returns a new iterator that first yields the elements of this * iterator followed by the elements provided by iterator <code>that</code>. */ - def ++[B >: A](that: => Iterator[B]) = new Iterator[B] { + def ++[B >: A](that: => Iterator[B]): Iterator[B] = new Iterator[B] { // optimize a little bit to prevent n log n behavior. - var cur : Iterator[B] = self - def hasNext = cur.hasNext || (cur eq self) && { cur = that; hasNext } + private var cur : Iterator[B] = self + // this was unnecessarily looping forever on x ++ x + def hasNext = cur.hasNext || ((cur eq self) && { + val it = that + it.hasNext && { + cur = it + true + } + }) def next() = { hasNext; cur.next() } } @@ -1073,10 +1080,7 @@ trait Iterator[+A] { self => * iterator followed by the elements provided by iterator <code>that</code>. */ @deprecated("use <code>++</code>") - def append[B >: A](that: Iterator[B]) = new Iterator[B] { - def hasNext = self.hasNext || that.hasNext - def next() = (if (self.hasNext) self else that).next() - } + def append[B >: A](that: Iterator[B]) = self ++ that /** Returns index of the first element satisfying a predicate, or -1. */ @deprecated("use `indexWhere` instead") |