Skip to content

Commit 48cffd0

Browse files
committed
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.
1 parent d526f8b commit 48cffd0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/library/scala/collection/mutable/MutableList.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extends AbstractSeq[A]
6565
require(nonEmpty, "tail of empty list")
6666
tl.first0 = first0.tail
6767
tl.len = len - 1
68-
tl.last0 = if (tl.len == 0) new LinkedList[A]() else last0
68+
tl.last0 = if (tl.len == 0) tl.first0 else last0
6969
}
7070

7171
/** Prepends a single element to this list. This operation takes constant

src/library/scala/collection/mutable/Queue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ extends MutableList[A]
183183

184184
private[this] def decrementLength() {
185185
len -= 1
186-
if (len == 0) last0 = new LinkedList[A]()
186+
if (len == 0) last0 = first0
187187
}
188188
}
189189

0 commit comments

Comments
 (0)