summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorIchoran <ichoran@gmail.com>2015-02-04 14:28:51 -0800
committerIchoran <ichoran@gmail.com>2015-02-04 14:28:51 -0800
commit67fd6557af837b19ff68f9292790bd293ce8009b (patch)
treeca509d96c4544f3f25903e93f638ed7319530442 /src/library
parent745ed5c8f6431400cb432cfec751351b3bbd88f0 (diff)
parent6ba7068b9f0389812bb03eae88c31035ad73c1aa (diff)
downloadscala-67fd6557af837b19ff68f9292790bd293ce8009b.tar.gz
scala-67fd6557af837b19ff68f9292790bd293ce8009b.tar.bz2
scala-67fd6557af837b19ff68f9292790bd293ce8009b.zip
Merge pull request #4133 from som-snytt/issue/8976
SI-8976 MutableList.tail.iterator.size is length
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/mutable/MutableList.scala17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala
index b852a4747b..646023f469 100644
--- a/src/library/scala/collection/mutable/MutableList.scala
+++ b/src/library/scala/collection/mutable/MutableList.scala
@@ -13,7 +13,6 @@ package mutable
import generic._
import immutable.{List, Nil}
-// !!! todo: convert to LinkedListBuffer?
/**
* This class is used internally to represent mutable lists. It is the
* basis for the implementation of the class `Queue`.
@@ -113,9 +112,21 @@ extends AbstractSeq[A]
}
}
- /** Returns an iterator over all elements of this list.
+ /** Returns an iterator over up to `length` elements of this list.
*/
- override def iterator: Iterator[A] = first0.iterator
+ override def iterator: Iterator[A] = if (isEmpty) Iterator.empty else
+ new AbstractIterator[A] {
+ var elems = first0
+ var count = len
+ def hasNext = count > 0 && elems.nonEmpty
+ def next() = {
+ if (!hasNext) throw new NoSuchElementException
+ count = count - 1
+ val e = elems.elem
+ elems = if (count == 0) null else elems.next
+ e
+ }
+ }
override def last = {
if (isEmpty) throw new NoSuchElementException("MutableList.empty.last")