diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-04 09:26:31 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-04 09:26:31 +0200 |
commit | 8ef38973db5474ed44c921d81e7cbaa641056fca (patch) | |
tree | cb13d600175fb10d6b59dce842ff8534ddf3b6cf /src/library | |
parent | 4dcb51c5a15aa5f2ddd27ae19453364706bc72ea (diff) | |
parent | 36ef5c374a11f881cb77bcb784af7b52483ee646 (diff) | |
download | scala-8ef38973db5474ed44c921d81e7cbaa641056fca.tar.gz scala-8ef38973db5474ed44c921d81e7cbaa641056fca.tar.bz2 scala-8ef38973db5474ed44c921d81e7cbaa641056fca.zip |
Merge pull request #3840 from Ichoran/issue/8638
SI-8638 Empty UnrolledBuffer hangs on prepend.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/mutable/UnrolledBuffer.scala | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala index 1f89199bdc..693c47d86e 100644 --- a/src/library/scala/collection/mutable/UnrolledBuffer.scala +++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala @@ -300,27 +300,33 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] { if (next eq null) true else false // checks if last node was thrown out } else false - @tailrec final def insertAll(idx: Int, t: scala.collection.Traversable[T], buffer: UnrolledBuffer[T]): Unit = if (idx < size) { - // divide this node at the appropriate position and insert all into head - // update new next - val newnextnode = new Unrolled[T](0, new Array(array.length), null, buff) - Array.copy(array, idx, newnextnode.array, 0, size - idx) - newnextnode.size = size - idx - newnextnode.next = next - - // update this - nullout(idx, size) - size = idx - next = null - - // insert everything from iterable to this - var curr = this - for (elem <- t) curr = curr append elem - curr.next = newnextnode - - // try to merge the last node of this with the newnextnode - if (curr.tryMergeWithNext()) buffer.lastPtr = curr - } else insertAll(idx - size, t, buffer) + @tailrec final def insertAll(idx: Int, t: scala.collection.Traversable[T], buffer: UnrolledBuffer[T]): Unit = { + if (idx < size) { + // divide this node at the appropriate position and insert all into head + // update new next + val newnextnode = new Unrolled[T](0, new Array(array.length), null, buff) + Array.copy(array, idx, newnextnode.array, 0, size - idx) + newnextnode.size = size - idx + newnextnode.next = next + + // update this + nullout(idx, size) + size = idx + next = null + + // insert everything from iterable to this + var curr = this + for (elem <- t) curr = curr append elem + curr.next = newnextnode + + // try to merge the last node of this with the newnextnode + if (curr.tryMergeWithNext()) buffer.lastPtr = curr + } + else if (idx == size) { + var curr = this + for (elem <- t) curr = curr append elem + } else insertAll(idx - size, t, buffer) + } private def nullout(from: Int, until: Int) { var idx = from while (idx < until) { |