Skip to content

Commit

Permalink
Share the empty LinkedList between first0/last0.
Browse files Browse the repository at this point in the history
This is in line with the existing implementation
of `MutableList#clear`, and in line with an newly
created empty collection.
  • Loading branch information
retronym committed Dec 10, 2012
1 parent d526f8b commit 48cffd0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/MutableList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/mutable/Queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 48cffd0

Please sign in to comment.