summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/MutableList.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-12-08 09:30:42 +0100
committerJason Zaugg <jzaugg@gmail.com>2012-12-08 11:47:03 +0100
commitd526f8bd74a3a6b878dda77bf19beb60dbc28f81 (patch)
tree15696ceae54177d44e428fe73873b0d3f8c45a8a /src/library/scala/collection/mutable/MutableList.scala
parentfd57069a3a49de1757a518b573a0cd8cb98bbbd5 (diff)
downloadscala-d526f8bd74a3a6b878dda77bf19beb60dbc28f81.tar.gz
scala-d526f8bd74a3a6b878dda77bf19beb60dbc28f81.tar.bz2
scala-d526f8bd74a3a6b878dda77bf19beb60dbc28f81.zip
SI-6690 Release reference to last dequeued element.
Avoids leaks in MutableList and its more better known child, mutable.Queue, when the last element is dequeued or when we take the tail of a one element collection. Refactors copy/pasted code between the two implementations of tail.
Diffstat (limited to 'src/library/scala/collection/mutable/MutableList.scala')
-rw-r--r--src/library/scala/collection/mutable/MutableList.scala10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/library/scala/collection/mutable/MutableList.scala b/src/library/scala/collection/mutable/MutableList.scala
index 183de5b727..4bbe604cd3 100644
--- a/src/library/scala/collection/mutable/MutableList.scala
+++ b/src/library/scala/collection/mutable/MutableList.scala
@@ -56,12 +56,16 @@ extends AbstractSeq[A]
/** Returns the rest of this list
*/
override def tail: MutableList[A] = {
- require(nonEmpty, "tail of empty list")
val tl = new MutableList[A]
+ tailImpl(tl)
+ tl
+ }
+
+ protected final def tailImpl(tl: MutableList[A]) {
+ require(nonEmpty, "tail of empty list")
tl.first0 = first0.tail
- tl.last0 = last0
tl.len = len - 1
- tl
+ tl.last0 = if (tl.len == 0) new LinkedList[A]() else last0
}
/** Prepends a single element to this list. This operation takes constant