Skip to content

Commit

Permalink
Refactor VectorBuilder.clear in terms of the existing method preClean
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Jun 12, 2018
1 parent 63ec32a commit 845b0f0
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/library/scala/collection/immutable/Vector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -419,33 +419,6 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I
copy
}

private def preClean(depth: Int) = {
this.depth = depth
(depth - 1) match {
case 0 =>
display1 = null
display2 = null
display3 = null
display4 = null
display5 = null
case 1 =>
display2 = null
display3 = null
display4 = null
display5 = null
case 2 =>
display3 = null
display4 = null
display5 = null
case 3 =>
display4 = null
display5 = null
case 4 =>
display5 = null
case 5 =>
}
}

// requires structure is at index cutIndex and writable at level 0
private def cleanLeftEdge(cutIndex: Int) = {
if (cutIndex < (1 << 5)) {
Expand Down Expand Up @@ -652,13 +625,8 @@ final class VectorBuilder[A]() extends ReusableBuilder[A, Vector[A]] with Vector
}

def clear(): Unit = {
preClean(1)
display0 = new Array[AnyRef](32)
display1 = null
display2 = null
display3 = null
display4 = null
display5 = null
depth = 1
blockIndex = 0
lo = 0
}
Expand All @@ -673,7 +641,35 @@ private[immutable] trait VectorPointer[T] {
private[immutable] var display4: Array[AnyRef] = _
private[immutable] var display5: Array[AnyRef] = _

// used
protected def preClean(depth: Int): Unit = {
this.depth = depth
(depth - 1) match {
case 0 =>
display1 = null
display2 = null
display3 = null
display4 = null
display5 = null
case 1 =>
display2 = null
display3 = null
display4 = null
display5 = null
case 2 =>
display3 = null
display4 = null
display5 = null
case 3 =>
display4 = null
display5 = null
case 4 =>
display5 = null
case 5 =>
}
}


// used
private[immutable] final def initFrom[U](that: VectorPointer[U]): Unit = initFrom(that, that.depth)

private[immutable] final def initFrom[U](that: VectorPointer[U], depth: Int) = {
Expand Down

0 comments on commit 845b0f0

Please sign in to comment.