Permalink
Browse files

Share the empty LinkedList between first0/last0.

This is in line with the existing implementation
of `MutableList#clear`, and in line with an newly
created empty collection.
  • Loading branch information...
1 parent d526f8b commit 48cffd0589ed9a470f351ab9518b02a033c759eb @retronym retronym committed Dec 10, 2012
View
2 src/library/scala/collection/mutable/MutableList.scala
@@ -65,7 +65,7 @@ extends AbstractSeq[A]
require(nonEmpty, "tail of empty list")
tl.first0 = first0.tail
tl.len = len - 1
- tl.last0 = if (tl.len == 0) new LinkedList[A]() else last0
+ tl.last0 = if (tl.len == 0) tl.first0 else last0
}
/** Prepends a single element to this list. This operation takes constant
View
2 src/library/scala/collection/mutable/Queue.scala
@@ -183,7 +183,7 @@ extends MutableList[A]
private[this] def decrementLength() {
len -= 1
- if (len == 0) last0 = new LinkedList[A]()
+ if (len == 0) last0 = first0
}
}

0 comments on commit 48cffd0

Please sign in to comment.