diff options
author | Paul Phillips <paulp@improving.org> | 2010-09-17 00:16:33 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-09-17 00:16:33 +0000 |
commit | 99fb2b420f2fbf0eca5a98d0e52f8c6b580cd18f (patch) | |
tree | d86f3e56692a99769e88149a1eb4a621b968bf41 /src | |
parent | 4fe2d213ce613cf88d30b7ff1285cd74d4e32942 (diff) | |
download | scala-99fb2b420f2fbf0eca5a98d0e52f8c6b580cd18f.tar.gz scala-99fb2b420f2fbf0eca5a98d0e52f8c6b580cd18f.tar.bz2 scala-99fb2b420f2fbf0eca5a98d0e52f8c6b580cd18f.zip |
Does what can probably be done about strange it...
Does what can probably be done about strange iterator exhaustion
behavior. Maybe we should start thinking about iteratees... Closes
#3760, no review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/LinearSeqLike.scala | 10 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Stream.scala | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala index c2c4996f47..8bf45348db 100644 --- a/src/library/scala/collection/LinearSeqLike.scala +++ b/src/library/scala/collection/LinearSeqLike.scala @@ -56,6 +56,14 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr if (hasNext) { val result = these.head; these = these.tail; result } else Iterator.empty.next - override def toList: List[A] = these.toList + + /** Have to clear these so the iterator is exhausted like + * it would be without the optimization. + */ + override def toList: List[A] = { + val xs = these.toList + these = newBuilder.result + xs + } } } diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 5339b29e7c..02a17427ef 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -262,7 +262,11 @@ self => these = new LazyCell(cur.tail) result } - override def toStream = these.v + override def toStream = { + val result = these.v + these = new LazyCell(Stream.empty) + result + } override def toList = toStream.toList } |