diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index 362b9d8838cd..2ca5e711d054 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -5,6 +5,7 @@ package immutable import scala.collection.mutable.{Builder, ReusableBuilder} import scala.annotation.unchecked.uncheckedVariance +import scala.runtime.ScalaRunTime /** $factoryInfo * @define Coll `Vector` @@ -218,6 +219,7 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I s.dirty = dirty s.gotoPosWritable(focus, idx, focus ^ idx) // if dirty commit changes; go to new pos and prepare for writing s.display0(idx & 31) = elem.asInstanceOf[AnyRef] + ScalaRunTime.releaseFence() s } @@ -236,7 +238,7 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I } override def prepended[B >: A](value: B): Vector[B] = { - if (endIndex != startIndex) { + val result = if (endIndex != startIndex) { val blockIndex = (startIndex - 1) & ~31 val lo = (startIndex - 1) & 31 @@ -311,10 +313,12 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I s.display0 = elems s } + ScalaRunTime.releaseFence() + result } override def appended[B >: A](value: B): Vector[B] = { - if (endIndex != startIndex) { + val result = if (endIndex != startIndex) { val blockIndex = endIndex & ~31 val lo = endIndex & 31 @@ -373,6 +377,8 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I s.display0 = elems s } + ScalaRunTime.releaseFence() + result } @@ -536,6 +542,7 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I s.gotoPosWritable(focus, blockIndex, focus ^ blockIndex) s.preClean(d) s.cleanLeftEdge(cutIndex - shift) + ScalaRunTime.releaseFence() s } @@ -551,6 +558,7 @@ final class Vector[+A] private[immutable] (private[collection] val startIndex: I s.gotoPosWritable(focus, blockIndex, focus ^ blockIndex) s.preClean(d) s.cleanRightEdge(cutIndex - shift) + ScalaRunTime.releaseFence() s } @@ -641,6 +649,7 @@ final class VectorBuilder[A]() extends ReusableBuilder[A, Vector[A]] with Vector val s = new Vector[A](0, size, 0) // should focus front or back? s.initFrom(this) if (depth > 1) s.gotoPos(0, size - 1) // we're currently focused to size - 1, not size! + ScalaRunTime.releaseFence() s }