diff options
Diffstat (limited to 'src/library/scalax/collection/mutable')
-rw-r--r-- | src/library/scalax/collection/mutable/ArrayBuffer.scala | 13 | ||||
-rw-r--r-- | src/library/scalax/collection/mutable/ResizableArray.scala | 5 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/library/scalax/collection/mutable/ArrayBuffer.scala b/src/library/scalax/collection/mutable/ArrayBuffer.scala index e08102afb3..df7f6ba758 100644 --- a/src/library/scalax/collection/mutable/ArrayBuffer.scala +++ b/src/library/scalax/collection/mutable/ArrayBuffer.scala @@ -23,9 +23,7 @@ package scalax.collection.mutable @serializable class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with ResizableArray[A] { - def clear() { - size0 = 0 - } + def clear() { reduceToSize(0) } /** Appends a single element to this buffer and returns * the identity of the buffer. It takes constant time. @@ -45,7 +43,14 @@ class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with Resizab * @param iter the iterable object. * @return the updated buffer. */ - override def ++=(iter: Iterable[A]) { iter copyToBuffer this } + override def ++=(iter: Iterable[A]) = iter match { + case v: Vector[A] => + val n = v.length + ensureSize(size0 + n) + v.copyToArray(array.asInstanceOf[Array[Any]], n) + case _ => + super.++=(iter) + } /** Prepends a single element to this buffer and return * the identity of the buffer. It takes time linear in diff --git a/src/library/scalax/collection/mutable/ResizableArray.scala b/src/library/scalax/collection/mutable/ResizableArray.scala index 5a9e81f069..93a4c7753a 100644 --- a/src/library/scalax/collection/mutable/ResizableArray.scala +++ b/src/library/scalax/collection/mutable/ResizableArray.scala @@ -72,7 +72,10 @@ trait ResizableArray[A] extends Vector[A] { */ def reduceToSize(sz: Int) { require(sz <= size0) - size0 = sz + while (size0 > sz) { + size0 -= 1 + array(size0) = null + } } /** ensure that the internal array has at n cells */ |