@@ -18,6 +18,7 @@ import scala.collection.generic.DefaultSerializable
1818import  scala .reflect .ClassTag 
1919import  scala .collection .immutable .Nil 
2020import  language .experimental .captureChecking 
21+ import  caps .unsafe .unsafeAssumePure 
2122
2223/**  A buffer that stores elements in an unrolled linked list.
2324  * 
@@ -259,13 +260,14 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
259260  /**  Unrolled buffer node. 
260261    */  
261262  class  Unrolled [T :  ClassTag ] private [collection] (var  size :  Int , var  array :  Array [T ], var  next :  Unrolled [T ], val  buff :  UnrolledBuffer [T ] =  null ) {
263+     // this: Unrolled[T]^ =>
262264    private [collection] def  this () =  this (0 , new  Array [T ](unrolledlength), null , null )
263265    private [collection] def  this (b : UnrolledBuffer [T ]) =  this (0 , new  Array [T ](unrolledlength), null , b)
264266
265267    private  def  nextlength  =  if  (buff eq null ) unrolledlength else  buff.calcNextLength(array.length)
266268
267269    //  adds and returns itself or the new unrolled if full
268-     @ tailrec final  def  append (elem : T ):  Unrolled [T ] =  if  (size <  array.length) {
270+     @ tailrec final  def  append (elem : T ):  Unrolled [T ]^ { this }  =  if  (size <  array.length) {
269271      array(size) =  elem
270272      size +=  1 
271273      this 
@@ -307,21 +309,21 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
307309      if  (idx <  size) array(idx) else  next.apply(idx -  size)
308310    @ tailrec final  def  update (idx : Int , newelem : T ):  Unit  = 
309311      if  (idx <  size) array(idx) =  newelem else  next.update(idx -  size, newelem)
310-     @ tailrec final  def  locate (idx : Int ):  Unrolled [T ] = 
312+     @ tailrec final  def  locate (idx : Int ):  Unrolled [T ]^ { this }  = 
311313      if  (idx <  size) this  else  next.locate(idx -  size)
312-     def  prepend (elem : T ) =  if  (size <  array.length) {
314+     def  prepend (elem : T ):   Unrolled [ T ]  =  if  (size <  array.length) {
313315      //  shift the elements of the array right
314316      //  then insert the element
315317      shiftright()
316318      array(0 ) =  elem
317319      size +=  1 
318-       this 
320+       this .unsafeAssumePure 
319321    } else  {
320322      //  allocate a new node and store element
321323      //  then make it point to this
322324      val  newhead  =  new  Unrolled [T ](buff)
323325      newhead append elem
324-       newhead.next =  this 
326+       newhead.next =  this .unsafeAssumePure 
325327      newhead
326328    }
327329    //  shifts right assuming enough space
@@ -340,7 +342,7 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
340342        val  r  =  array(idx)
341343        shiftleft(idx)
342344        size -=  1 
343-         if  (tryMergeWithNext()) buffer.lastPtr =  this 
345+         if  (tryMergeWithNext()) buffer.lastPtr =  this .unsafeAssumePure 
344346        r
345347      } else  next.remove(idx -  size, buffer)
346348
@@ -397,7 +399,7 @@ object UnrolledBuffer extends StrictOptimizedClassTagSeqFactory[UnrolledBuffer]
397399        curr.next =  newnextnode
398400
399401        //  try to merge the last node of this with the newnextnode and fix tail pointer if needed
400-         if  (curr.tryMergeWithNext()) buffer.lastPtr =  curr
402+         if  (curr.tryMergeWithNext()) buffer.lastPtr =  curr.unsafeAssumePure 
401403        else  if  (newnextnode.next eq null ) buffer.lastPtr =  newnextnode
402404        appended
403405      }
0 commit comments