@@ -208,7 +208,7 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
208
208
def newBuilder [T ](implicit t : ClassTag [T ]): Builder [T , UnrolledBuffer [T ]] = new UnrolledBuffer [T ]
209
209
210
210
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.)
212
212
private [collection] val unrolledlength = 32
213
213
214
214
/** Unrolled buffer node.
@@ -319,13 +319,15 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
319
319
for (elem <- t) curr = curr append elem
320
320
curr.next = newnextnode
321
321
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
323
323
if (curr.tryMergeWithNext()) buffer.lastPtr = curr
324
+ else if (newnextnode.next eq null ) buffer.lastPtr = newnextnode
324
325
}
325
- else if (idx == size) {
326
+ else if (idx == size || (next eq null ) ) {
326
327
var curr = this
327
328
for (elem <- t) curr = curr append elem
328
- } else insertAll(idx - size, t, buffer)
329
+ }
330
+ else next.insertAll(idx - size, t, buffer)
329
331
}
330
332
private def nullout (from : Int , until : Int ) {
331
333
var idx = from
@@ -344,7 +346,7 @@ object UnrolledBuffer extends ClassTagTraversableFactory[UnrolledBuffer] {
344
346
tryMergeWithNext()
345
347
}
346
348
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 " " )
348
350
}
349
351
350
352
}
0 commit comments