@@ -208,7 +208,7 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
208208 def newBuilder [T ](implicit t : ClassTag [T ]): Builder [T , UnrolledBuffer [T ]] = new UnrolledBuffer [T ]
209209
210210 val waterline = 50
211- val waterlineDelim = 100
211+ val waterlineDelim = 100 // TODO -- fix this name! It's a denominator, not a delimiter. (But it's part of the API so we can't just change it.)
212212 private [collection] val unrolledlength = 32
213213
214214 /** Unrolled buffer node.
@@ -319,13 +319,15 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
319319 for (elem <- t) curr = curr append elem
320320 curr.next = newnextnode
321321
322- // try to merge the last node of this with the newnextnode
322+ // try to merge the last node of this with the newnextnode and fix tail pointer if needed
323323 if (curr.tryMergeWithNext()) buffer.lastPtr = curr
324+ else if (newnextnode.next eq null ) buffer.lastPtr = newnextnode
324325 }
325- else if (idx == size) {
326+ else if (idx == size || (next eq null ) ) {
326327 var curr = this
327328 for (elem <- t) curr = curr append elem
328- } else insertAll(idx - size, t, buffer)
329+ }
330+ else next.insertAll(idx - size, t, buffer)
329331 }
330332 private def nullout (from : Int , until : Int ) {
331333 var idx = from
@@ -344,7 +346,7 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
344346 tryMergeWithNext()
345347 }
346348
347- override def toString = array.take(size).mkString(" Unrolled[ " + array.length + " ](" , " , " , " )" ) + " -> " + (if (next ne null ) next.toString else " " )
349+ override def toString = array.take(size).mkString(" Unrolled@%08x " .format( System .identityHashCode( this )) + " [ " + size + " / " + array.length + " ](" , " , " , " )" ) + " -> " + (if (next ne null ) next.toString else " " )
348350 }
349351
350352}
0 commit comments