diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-12-15 16:16:19 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-12-15 16:16:19 +0100 |
commit | 7ba38a07916426314cc3bff6999f3992757e0b26 (patch) | |
tree | 64786d4272ec26e7da6bc5e62c3fdfec334c318f /src/library | |
parent | 371a28ba0a604a45360e3de17bd186a245fb5a60 (diff) | |
parent | 6e8c60eabbbf0f21ef8e0b87267952bec2f85159 (diff) | |
download | scala-7ba38a07916426314cc3bff6999f3992757e0b26.tar.gz scala-7ba38a07916426314cc3bff6999f3992757e0b26.tar.bz2 scala-7ba38a07916426314cc3bff6999f3992757e0b26.zip |
Merge pull request #4202 from kanielc/SI-9043
SI-9043 ArrayBuffer.insert and insertAll are very slow
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/mutable/ArrayBuffer.scala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala index 8f77114746..011fd415ee 100644 --- a/src/library/scala/collection/mutable/ArrayBuffer.scala +++ b/src/library/scala/collection/mutable/ArrayBuffer.scala @@ -128,7 +128,7 @@ class ArrayBuffer[A](override protected val initialSize: Int) override def ++=:(xs: TraversableOnce[A]): this.type = { insertAll(0, xs.toTraversable); this } /** Inserts new elements at the index `n`. Opposed to method - * `update`, this method will not replace an element with a + * `update`, this method will not replace an element with a new * one. Instead, it will insert a new element at index `n`. * * @param n the index where a new element will be inserted. @@ -137,12 +137,13 @@ class ArrayBuffer[A](override protected val initialSize: Int) */ def insertAll(n: Int, seq: Traversable[A]) { if (n < 0 || n > size0) throw new IndexOutOfBoundsException(n.toString) - val xs = seq.toList - val len = xs.length - ensureSize(size0 + len) + val len = seq.size + val newSize = size0 + len + ensureSize(newSize) + copy(n, n + len, size0 - n) - xs.copyToArray(array.asInstanceOf[scala.Array[Any]], n) - size0 += len + seq.copyToArray(array.asInstanceOf[Array[Any]], n) + size0 = newSize } /** Removes the element on a given index position. It takes time linear in |