summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-08-23 16:57:10 +0000
committerPaul Phillips <paulp@improving.org>2010-08-23 16:57:10 +0000
commit79a7191e605d22ffe9d2142039f586682c6902d6 (patch)
treea2efb969100277f161929523591a96d6f4a5902d /src
parent3db5daf609b4c67ce1a236eb4c99a0fdc008581d (diff)
downloadscala-79a7191e605d22ffe9d2142039f586682c6902d6.tar.gz
scala-79a7191e605d22ffe9d2142039f586682c6902d6.tar.bz2
scala-79a7191e605d22ffe9d2142039f586682c6902d6.zip
Fix and test case for broken linked lists, cont...
Fix and test case for broken linked lists, contributed by Lucien Pereira. Closes #3361, no review.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/mutable/DoubleLinkedList.scala16
-rw-r--r--src/library/scala/collection/mutable/LinkedListLike.scala3
2 files changed, 12 insertions, 7 deletions
diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala
index e702301703..d3c86953c8 100644
--- a/src/library/scala/collection/mutable/DoubleLinkedList.scala
+++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala
@@ -69,15 +69,21 @@ object DoubleLinkedList extends SeqFactory[DoubleLinkedList] {
def newBuilder[A]: Builder[A, DoubleLinkedList[A]] =
new Builder[A, DoubleLinkedList[A]] {
var current: DoubleLinkedList[A] = _
+ val emptyList = new DoubleLinkedList[A]()
+ if(null == current)
+ current = emptyList
+
def +=(elem: A): this.type = {
- val tmp = new DoubleLinkedList(elem, null)
- if (current != null)
- current.insert(tmp)
+ if (current.nonEmpty)
+ current.insert(new DoubleLinkedList(elem, emptyList))
else
- current = tmp
+ current = new DoubleLinkedList(elem, emptyList)
this
}
- def clear() { current = null }
+
+ def clear() {
+ current = emptyList
+ }
def result() = current
}
}
diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala
index ca904e0a24..6fb516d566 100644
--- a/src/library/scala/collection/mutable/LinkedListLike.scala
+++ b/src/library/scala/collection/mutable/LinkedListLike.scala
@@ -66,8 +66,7 @@ trait LinkedListLike[A, This <: Seq[A] with LinkedListLike[A, This]] extends Seq
def insert(that: This): Unit = {
require(nonEmpty, "insert into empty list")
if (that.nonEmpty) {
- that.append(next)
- next = that
+ next = next.append(that)
}
}