diff options
Diffstat (limited to 'src/library')
33 files changed, 216 insertions, 192 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 5b8ebde308..fd61cfd0a1 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -12,17 +12,17 @@ import scala.collection.generic._ import scala.collection.{ mutable, immutable } import mutable.{ ArrayBuilder, ArraySeq } import compat.Platform.arraycopy -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag import scala.runtime.ScalaRunTime.{ array_apply, array_update } /** Contains a fallback builder for arrays when the element type - * does not have a class manifest. In that case a generic array is built. + * does not have a class tag. In that case a generic array is built. */ class FallbackArrayBuilding { /** A builder factory that generates a generic array. * Called instead of `Array.newBuilder` if the element type of an array - * does not have a class manifest. Note that fallbackBuilder factory + * does not have a class tag. Note that fallbackBuilder factory * needs an implicit parameter (otherwise it would not be dominated in * implicit search by `Array.canBuildFrom`). We make sure that * implicit search is always successful. @@ -48,16 +48,16 @@ class FallbackArrayBuilding { * @version 1.0 */ object Array extends FallbackArrayBuilding { - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Array[_], T, Array[T]] = + implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Array[_], T, Array[T]] = new CanBuildFrom[Array[_], T, Array[T]] { - def apply(from: Array[_]) = ArrayBuilder.make[T]()(m) - def apply() = ArrayBuilder.make[T]()(m) + def apply(from: Array[_]) = ArrayBuilder.make[T]()(t) + def apply() = ArrayBuilder.make[T]()(t) } /** * Returns a new [[scala.collection.mutable.ArrayBuilder]]. */ - def newBuilder[T](implicit m: ClassManifest[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(m) + def newBuilder[T](implicit t: ArrayTag[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(t) private def slowcopy(src : AnyRef, srcPos : Int, @@ -98,14 +98,14 @@ object Array extends FallbackArrayBuilding { } /** Returns an array of length 0 */ - def empty[T: ClassManifest]: Array[T] = new Array[T](0) + def empty[T: ArrayTag]: Array[T] = new Array[T](0) /** Creates an array with given elements. * * @param xs the elements to put in the array * @return an array containing all elements from xs. */ - def apply[T: ClassManifest](xs: T*): Array[T] = { + def apply[T: ArrayTag](xs: T*): Array[T] = { val array = new Array[T](xs.length) var i = 0 for (x <- xs.iterator) { array(i) = x; i += 1 } @@ -194,23 +194,23 @@ object Array extends FallbackArrayBuilding { } /** Creates array with given dimensions */ - def ofDim[T: ClassManifest](n1: Int): Array[T] = + def ofDim[T: ArrayTag](n1: Int): Array[T] = new Array[T](n1) /** Creates a 2-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int): Array[Array[T]] = { + def ofDim[T: ArrayTag](n1: Int, n2: Int): Array[Array[T]] = { val arr: Array[Array[T]] = (new Array[Array[T]](n1): Array[Array[T]]) for (i <- 0 until n1) arr(i) = new Array[T](n2) arr // tabulate(n1)(_ => ofDim[T](n2)) } /** Creates a 3-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int): Array[Array[Array[T]]] = tabulate(n1)(_ => ofDim[T](n2, n3)) /** Creates a 4-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4)) /** Creates a 5-dimensional array */ - def ofDim[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = + def ofDim[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => ofDim[T](n2, n3, n4, n5)) /** Concatenates all arrays into a single array. @@ -218,7 +218,7 @@ object Array extends FallbackArrayBuilding { * @param xss the given arrays * @return the array created from concatenating `xss` */ - def concat[T: ClassManifest](xss: Array[T]*): Array[T] = { + def concat[T: ArrayTag](xss: Array[T]*): Array[T] = { val b = newBuilder[T] b.sizeHint(xss.map(_.size).sum) for (xs <- xss) b ++= xs @@ -239,7 +239,7 @@ object Array extends FallbackArrayBuilding { * @return an Array of size n, where each element contains the result of computing * `elem`. */ - def fill[T: ClassManifest](n: Int)(elem: => T): Array[T] = { + def fill[T: ArrayTag](n: Int)(elem: => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -257,7 +257,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = + def fill[T: ArrayTag](n1: Int, n2: Int)(elem: => T): Array[Array[T]] = tabulate(n1)(_ => fill(n2)(elem)) /** Returns a three-dimensional array that contains the results of some element @@ -268,7 +268,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3nd dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int)(elem: => T): Array[Array[Array[T]]] = tabulate(n1)(_ => fill(n2, n3)(elem)) /** Returns a four-dimensional array that contains the results of some element @@ -280,7 +280,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(_ => fill(n2, n3, n4)(elem)) /** Returns a five-dimensional array that contains the results of some element @@ -293,7 +293,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param elem the element computation */ - def fill[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = + def fill[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(_ => fill(n2, n3, n4, n5)(elem)) /** Returns an array containing values of a given function over a range of integer @@ -303,7 +303,7 @@ object Array extends FallbackArrayBuilding { * @param f The function computing element values * @return A traversable consisting of elements `f(0),f(1), ..., f(n - 1)` */ - def tabulate[T: ClassManifest](n: Int)(f: Int => T): Array[T] = { + def tabulate[T: ArrayTag](n: Int)(f: Int => T): Array[T] = { val b = newBuilder[T] b.sizeHint(n) var i = 0 @@ -321,7 +321,7 @@ object Array extends FallbackArrayBuilding { * @param n2 the number of elements in the 2nd dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int)(f: (Int, Int) => T): Array[Array[T]] = tabulate(n1)(i1 => tabulate(n2)(f(i1, _))) /** Returns a three-dimensional array containing values of a given function @@ -332,7 +332,7 @@ object Array extends FallbackArrayBuilding { * @param n3 the number of elements in the 3rd dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int)(f: (Int, Int, Int) => T): Array[Array[Array[T]]] = tabulate(n1)(i1 => tabulate(n2, n3)(f(i1, _, _))) /** Returns a four-dimensional array containing values of a given function @@ -344,7 +344,7 @@ object Array extends FallbackArrayBuilding { * @param n4 the number of elements in the 4th dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int)(f: (Int, Int, Int, Int) => T): Array[Array[Array[Array[T]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4)(f(i1, _, _, _))) /** Returns a five-dimensional array containing values of a given function @@ -357,7 +357,7 @@ object Array extends FallbackArrayBuilding { * @param n5 the number of elements in the 5th dimension * @param f The function computing element values */ - def tabulate[T: ClassManifest](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = + def tabulate[T: ArrayTag](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(f: (Int, Int, Int, Int, Int) => T): Array[Array[Array[Array[Array[T]]]]] = tabulate(n1)(i1 => tabulate(n2, n3, n4, n5)(f(i1, _, _, _, _))) /** Returns an array containing a sequence of increasing integers in a range. @@ -396,7 +396,7 @@ object Array extends FallbackArrayBuilding { * @param f the function that is repeatedly applied * @return the array returning `len` values in the sequence `start, f(start), f(f(start)), ...` */ - def iterate[T: ClassManifest](start: T, len: Int)(f: T => T): Array[T] = { + def iterate[T: ArrayTag](start: T, len: Int)(f: T => T): Array[T] = { val b = newBuilder[T] if (len > 0) { @@ -476,7 +476,7 @@ object Array extends FallbackArrayBuilding { * @define collectExample * @define undefinedorder * @define thatinfo the class of the returned collection. In the standard library configuration, - * `That` is either `Array[B]` if a ClassManifest is available for B or `ArraySeq[B]` otherwise. + * `That` is either `Array[B]` if an ArrayTag is available for B or `ArraySeq[B]` otherwise. * @define zipthatinfo $thatinfo * @define bfinfo an implicit value of class `CanBuildFrom` which determines the result class `That` from the current * representation type `Repr` and the new element type `B`. diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala index a7ec7618b7..fd8595ccb8 100644 --- a/src/library/scala/collection/GenTraversableOnce.scala +++ b/src/library/scala/collection/GenTraversableOnce.scala @@ -459,7 +459,7 @@ trait GenTraversableOnce[+A] extends Any { /** Converts this $coll to an array. * - * @tparam B the type of the elements of the array. A `ClassManifest` for + * @tparam B the type of the elements of the array. An `ArrayTag` for * this type must be available. * @return an array containing all elements of this $coll. * @@ -469,9 +469,9 @@ trait GenTraversableOnce[+A] extends Any { * $willNotTerminateInf * * @return an array containing all elements of this $coll. - * A `ClassManifest` must be available for the element type of this $coll. + * An `ArrayTag` must be available for the element type of this $coll. */ - def toArray[A1 >: A: ClassManifest]: Array[A1] + def toArray[A1 >: A: ArrayTag]: Array[A1] /** Converts this $coll to a list. * $willNotTerminateInf diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index 3fba3dfa79..a65be3ffcc 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -75,7 +75,7 @@ trait Traversable[+A] extends TraversableLike[A, Traversable[A]] override def copyToBuffer[B >: A](dest: Buffer[B]) override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) override def copyToArray[B >: A](xs: Array[B], start: Int) - override def toArray[B >: A : ClassManifest]: Array[B] + override def toArray[B >: A : ArrayTag]: Array[B] override def toList: List[A] override def toIterable: Iterable[A] override def toSeq: Seq[A] diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index e68ef9e4de..5b5cee7f1b 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -229,7 +229,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { def copyToArray[B >: A](xs: Array[B]): Unit = copyToArray(xs, 0, xs.length) - def toArray[B >: A : ClassManifest]: Array[B] = { + def toArray[B >: A : ArrayTag]: Array[B] = { if (isTraversableAgain) { val result = new Array[B](size) copyToArray(result, 0) diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index e7e797391e..20880e369d 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -73,7 +73,7 @@ trait TraversableProxyLike[+A, +Repr <: TraversableLike[A, Repr] with Traversabl override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = self.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = self.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = self.copyToArray(xs) - override def toArray[B >: A: ClassManifest]: Array[B] = self.toArray + override def toArray[B >: A: ArrayTag]: Array[B] = self.toArray override def toList: List[A] = self.toList override def toIterable: Iterable[A] = self.toIterable override def toSeq: Seq[A] = self.toSeq diff --git a/src/library/scala/collection/generic/ClassManifestTraversableFactory.scala b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala index e418ca623f..d9ab17559e 100644 --- a/src/library/scala/collection/generic/ClassManifestTraversableFactory.scala +++ b/src/library/scala/collection/generic/ArrayTagTraversableFactory.scala @@ -11,7 +11,7 @@ package generic import language.higherKinds -/** A template for companion objects of `ClassManifestTraversable` and +/** A template for companion objects of `ClassTagTraversable` and * subclasses thereof. * * @define coll collection @@ -21,11 +21,11 @@ import language.higherKinds * @author Aleksandar Prokopec * @since 2.8 */ -abstract class ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] - extends GenericClassManifestCompanion[CC] { +abstract class ArrayTagTraversableFactory[CC[X] <: Traversable[X] with GenericArrayTagTraversableTemplate[X, CC]] + extends GenericArrayTagCompanion[CC] { - class GenericCanBuildFrom[A](implicit manif: ClassManifest[A]) extends CanBuildFrom[CC[_], A, CC[A]] { - def apply(from: CC[_]) = from.genericClassManifestBuilder[A] + class GenericCanBuildFrom[A](implicit tag: ArrayTag[A]) extends CanBuildFrom[CC[_], A, CC[A]] { + def apply(from: CC[_]) = from.genericArrayTagBuilder[A] def apply = newBuilder[A] } } diff --git a/src/library/scala/collection/generic/GenericClassManifestCompanion.scala b/src/library/scala/collection/generic/GenericArrayTagCompanion.scala index f357091361..959adbce6d 100644 --- a/src/library/scala/collection/generic/GenericClassManifestCompanion.scala +++ b/src/library/scala/collection/generic/GenericArrayTagCompanion.scala @@ -12,19 +12,19 @@ package generic import mutable.Builder import language.higherKinds -/** This class represents companions of classes which require ClassManifests +/** This class represents companions of classes which require ArrayTags * for their element types. * * @author Aleksandar Prokopec */ -abstract class GenericClassManifestCompanion[+CC[X] <: Traversable[X]] { +abstract class GenericArrayTagCompanion[+CC[X] <: Traversable[X]] { type Coll = CC[_] - def newBuilder[A](implicit ord: ClassManifest[A]): Builder[A, CC[A]] + def newBuilder[A](implicit ord: ArrayTag[A]): Builder[A, CC[A]] - def empty[A: ClassManifest]: CC[A] = newBuilder[A].result + def empty[A: ArrayTag]: CC[A] = newBuilder[A].result - def apply[A](elems: A*)(implicit ord: ClassManifest[A]): CC[A] = { + def apply[A](elems: A*)(implicit ord: ArrayTag[A]): CC[A] = { val b = newBuilder[A] b ++= elems b.result diff --git a/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala b/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala new file mode 100644 index 0000000000..ac84683c59 --- /dev/null +++ b/src/library/scala/collection/generic/GenericArrayTagTraversableTemplate.scala @@ -0,0 +1,30 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection +package generic + +import mutable.Builder +import annotation.unchecked.uncheckedVariance +import language.higherKinds + +/** This trait represents collections classes which require array + * tags for their element types. + * + * @author Aleksandar Prokopec + * @since 2.8 + */ +trait GenericArrayTagTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { + implicit protected[this] val tag: ArrayTag[A] + def arrayTagCompanion: GenericArrayTagCompanion[CC] + def genericArrayTagBuilder[B](implicit tag: ArrayTag[B]): Builder[B, CC[B]] = arrayTagCompanion.newBuilder[B] + @deprecated("use arrayTagCompanion instead", "2.10.0") + def classManifestCompanion: GenericClassManifestCompanion[CC] = arrayTagCompanion + @deprecated("use genericArrayTagBuilder instead", "2.10.0") + def genericClassManifestBuilder[B](implicit manifest: ClassManifest[B]): Builder[B, CC[B]] = genericArrayTagBuilder[B](manifest) +} diff --git a/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala b/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala deleted file mode 100644 index 1a5db4bab2..0000000000 --- a/src/library/scala/collection/generic/GenericClassManifestTraversableTemplate.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2010-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.collection -package generic - -import mutable.Builder -import annotation.unchecked.uncheckedVariance -import language.higherKinds - -/** This trait represents collections classes which require class - * manifests for their element types. - * - * @author Aleksandar Prokopec - * @since 2.8 - */ -trait GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A] @uncheckedVariance] { - implicit protected[this] val manifest: ClassManifest[A] - def classManifestCompanion: GenericClassManifestCompanion[CC] - def genericClassManifestBuilder[B](implicit man: ClassManifest[B]): Builder[B, CC[B]] = classManifestCompanion.newBuilder[B] -} diff --git a/src/library/scala/collection/generic/TraversableForwarder.scala b/src/library/scala/collection/generic/TraversableForwarder.scala index 3d723a1feb..3d5bc2704f 100644 --- a/src/library/scala/collection/generic/TraversableForwarder.scala +++ b/src/library/scala/collection/generic/TraversableForwarder.scala @@ -57,7 +57,7 @@ trait TraversableForwarder[+A] extends Traversable[A] { override def copyToArray[B >: A](xs: Array[B], start: Int, len: Int) = underlying.copyToArray(xs, start, len) override def copyToArray[B >: A](xs: Array[B], start: Int) = underlying.copyToArray(xs, start) override def copyToArray[B >: A](xs: Array[B]) = underlying.copyToArray(xs) - override def toArray[B >: A: ClassManifest]: Array[B] = underlying.toArray + override def toArray[B >: A: ArrayTag]: Array[B] = underlying.toArray override def toList: List[A] = underlying.toList override def toIterable: Iterable[A] = underlying.toIterable override def toSeq: Seq[A] = underlying.toSeq diff --git a/src/library/scala/collection/generic/package.scala b/src/library/scala/collection/generic/package.scala index 0457fef227..32006b4bf0 100644 --- a/src/library/scala/collection/generic/package.scala +++ b/src/library/scala/collection/generic/package.scala @@ -3,4 +3,13 @@ import generic.CanBuildFrom package object generic { type CanBuild[-Elem, +To] = CanBuildFrom[Nothing, Elem, To] + + @deprecated("use ArrayTagTraversableFactory instead", "2.10.0") + type ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ArrayTagTraversableFactory[CC] + + @deprecated("use GenericArrayTagCompanion instead", "2.10.0") + type GenericClassManifestCompanion[+CC[X] <: Traversable[X]] = GenericArrayTagCompanion[CC] + + @deprecated("use GenericArrayTagTraversableTemplate instead", "2.10.0") + type GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] = GenericArrayTagTraversableTemplate[A, CC] }
\ No newline at end of file diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala index 97c7c789f8..68c75ee586 100644 --- a/src/library/scala/collection/immutable/PagedSeq.scala +++ b/src/library/scala/collection/immutable/PagedSeq.scala @@ -25,7 +25,7 @@ object PagedSeq { final val UndeterminedEnd = Int.MaxValue /** Constructs a paged sequence from an iterator */ - def fromIterator[T: ClassManifest](source: Iterator[T]): PagedSeq[T] = + def fromIterator[T: ArrayTag](source: Iterator[T]): PagedSeq[T] = new PagedSeq[T]((data: Array[T], start: Int, len: Int) => { var i = 0 while (i < len && source.hasNext) { @@ -36,7 +36,7 @@ object PagedSeq { }) /** Constructs a paged sequence from an iterable */ - def fromIterable[T: ClassManifest](source: Iterable[T]): PagedSeq[T] = + def fromIterable[T: ArrayTag](source: Iterable[T]): PagedSeq[T] = fromIterator(source.iterator) /** Constructs a paged character sequence from a string iterator */ @@ -115,7 +115,7 @@ import PagedSeq._ * It returns the number of elements produced, or -1 if end of logical input stream was reached * before reading any element. * - * @tparam T the type of the elements contained in this paged sequence, with a `ClassManifest` context bound. + * @tparam T the type of the elements contained in this paged sequence, with an `ArrayTag` context bound. * * @author Martin Odersky * @since 2.7 @@ -124,7 +124,7 @@ import PagedSeq._ * @define mayNotTerminateInf * @define willNotTerminateInf */ -class PagedSeq[T: ClassManifest] protected( +class PagedSeq[T: ArrayTag] protected( more: (Array[T], Int, Int) => Int, first1: Page[T], start: Int, @@ -205,7 +205,7 @@ extends scala.collection.AbstractSeq[T] /** Page containing up to PageSize characters of the input sequence. */ -private class Page[T: ClassManifest](val num: Int) { +private class Page[T: ArrayTag](val num: Int) { private final val PageSize = 4096 diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 06f09f359f..52032a1cde 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -239,7 +239,7 @@ self => else throw new IllegalArgumentException("For input string: \"null\"") - override def toArray[B >: Char : ClassManifest]: Array[B] = + override def toArray[B >: Char : ArrayTag]: Array[B] = toString.toCharArray.asInstanceOf[Array[B]] private def unwrapArg(arg: Any): AnyRef = arg match { diff --git a/src/library/scala/collection/interfaces/IterableMethods.scala b/src/library/scala/collection/interfaces/IterableMethods.scala index 2054922e59..8efc3fe6f9 100644 --- a/src/library/scala/collection/interfaces/IterableMethods.scala +++ b/src/library/scala/collection/interfaces/IterableMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest import annotation.unchecked.uncheckedVariance /** diff --git a/src/library/scala/collection/interfaces/SeqMethods.scala b/src/library/scala/collection/interfaces/SeqMethods.scala index 1f5b08d036..4327073d21 100644 --- a/src/library/scala/collection/interfaces/SeqMethods.scala +++ b/src/library/scala/collection/interfaces/SeqMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest /** * @since 2.8 diff --git a/src/library/scala/collection/interfaces/SetMethods.scala b/src/library/scala/collection/interfaces/SetMethods.scala index ffe141ed82..3b6214f45c 100644 --- a/src/library/scala/collection/interfaces/SetMethods.scala +++ b/src/library/scala/collection/interfaces/SetMethods.scala @@ -11,7 +11,6 @@ package interfaces import generic._ import mutable.Buffer -import scala.reflect.ClassManifest import annotation.unchecked.uncheckedVariance /** diff --git a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala index 471e977134..543d59d118 100644 --- a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala @@ -46,7 +46,7 @@ trait TraversableOnceMethods[+A] { def copyToBuffer[B >: A](dest: mutable.Buffer[B]): Unit // conversions - def toArray[B >: A : ClassManifest]: Array[B] + def toArray[B >: A : ArrayTag]: Array[B] def toBuffer[B >: A]: mutable.Buffer[B] def toIndexedSeq: immutable.IndexedSeq[A] def toIterable: Iterable[A] diff --git a/src/library/scala/collection/mutable/ArrayBuilder.scala b/src/library/scala/collection/mutable/ArrayBuilder.scala index e396b0695e..293e85a97e 100644 --- a/src/library/scala/collection/mutable/ArrayBuilder.scala +++ b/src/library/scala/collection/mutable/ArrayBuilder.scala @@ -12,7 +12,8 @@ package scala.collection package mutable import generic._ -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime /** A builder class for arrays. * @@ -30,12 +31,12 @@ object ArrayBuilder { /** Creates a new arraybuilder of type `T`. * - * @tparam T type of the elements for the array builder, with a `ClassManifest` context bound. + * @tparam T type of the elements for the array builder, with a `ArrayTag` context bound. * @return a new empty array builder. */ - def make[T: ClassManifest](): ArrayBuilder[T] = { - val manifest = implicitly[ClassManifest[T]] - val erasure = manifest.erasure + def make[T: ArrayTag](): ArrayBuilder[T] = { + val tag = implicitly[ArrayTag[T]] + val erasure = ScalaRunTime.arrayElementClass(tag) erasure match { case java.lang.Byte.TYPE => new ArrayBuilder.ofByte().asInstanceOf[ArrayBuilder[T]] case java.lang.Short.TYPE => new ArrayBuilder.ofShort().asInstanceOf[ArrayBuilder[T]] @@ -46,15 +47,15 @@ object ArrayBuilder { case java.lang.Double.TYPE => new ArrayBuilder.ofDouble().asInstanceOf[ArrayBuilder[T]] case java.lang.Boolean.TYPE => new ArrayBuilder.ofBoolean().asInstanceOf[ArrayBuilder[T]] case java.lang.Void.TYPE => new ArrayBuilder.ofUnit().asInstanceOf[ArrayBuilder[T]] - case _ => new ArrayBuilder.ofRef[T with AnyRef]()(manifest.asInstanceOf[ClassManifest[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] + case _ => new ArrayBuilder.ofRef[T with AnyRef]()(tag.asInstanceOf[ArrayTag[T with AnyRef]]).asInstanceOf[ArrayBuilder[T]] } } /** A class for array builders for arrays of reference types. * - * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ClassManifest` context bound. + * @tparam T type of elements for the array builder, subtype of `AnyRef` with a `ArrayTag` context bound. */ - class ofRef[T <: AnyRef : ClassManifest] extends ArrayBuilder[T] { + class ofRef[T <: AnyRef : ArrayTag] extends ArrayBuilder[T] { private var elems: Array[T] = _ private var capacity: Int = 0 diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index 875030ade0..5f0e1e1071 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -12,7 +12,8 @@ package scala.collection package mutable import compat.Platform.arraycopy -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ import parallel.mutable.ParArray @@ -37,10 +38,8 @@ import parallel.mutable.ParArray */ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParallelizable[T, ParArray[T]] { - private def rowBuilder[U]: Builder[U, Array[U]] = - Array.newBuilder( - ClassManifest[U]( - repr.getClass.getComponentType.getComponentType)) + private def elementClass: Class[_] = + arrayElementClass(repr.getClass) override def copyToArray[U >: T](xs: Array[U], start: Int, len: Int) { var l = math.min(len, repr.length) @@ -48,11 +47,13 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza Array.copy(repr, 0, xs, start, l) } - override def toArray[U >: T : ClassManifest]: Array[U] = - if (implicitly[ClassManifest[U]].erasure eq repr.getClass.getComponentType) + override def toArray[U >: T : ArrayTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + if (elementClass eq thatElementClass) repr.asInstanceOf[Array[U]] else super.toArray[U] + } override def par = ParArray.handoff(repr) @@ -63,7 +64,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza * @param asArray A function that converts elements of this array to rows - arrays of type `U`. * @return An array obtained by concatenating rows of this array. */ - def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ClassManifest[U]): Array[U] = { + def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ArrayTag[U]): Array[U] = { val b = Array.newBuilder[U] b.sizeHint(map{case is: collection.IndexedSeq[_] => is.size case _ => 0}.sum) for (xs <- this) @@ -78,7 +79,8 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza * @return An array obtained by replacing elements of this arrays with rows the represent. */ def transpose[U](implicit asArray: T => Array[U]): Array[Array[U]] = { - val bs = asArray(head) map (_ => rowBuilder[U]) + def mkRowBuilder() = Array.newBuilder(ClassTag[U](arrayElementClass(elementClass))) + val bs = asArray(head) map (_ => mkRowBuilder()) for (xs <- this) { var i = 0 for (x <- asArray(xs)) { @@ -86,9 +88,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza i += 1 } } - val bb: Builder[Array[U], Array[Array[U]]] = Array.newBuilder( - ClassManifest[Array[U]]( - repr.getClass.getComponentType)) + val bb: Builder[Array[U], Array[Array[U]]] = Array.newBuilder(ClassTag[Array[U]](elementClass)) for (b <- bs) bb += b.result bb.result } @@ -109,8 +109,7 @@ object ArrayOps { override protected[this] def thisCollection: WrappedArray[T] = new WrappedArray.ofRef[T](repr) override protected[this] def toCollection(repr: Array[T]): WrappedArray[T] = new WrappedArray.ofRef[T](repr) - override protected[this] def newBuilder = new ArrayBuilder.ofRef[T]()( - ClassManifest[T](repr.getClass.getComponentType)) + override protected[this] def newBuilder = new ArrayBuilder.ofRef[T]()(ClassTag[T](arrayElementClass(repr.getClass))) def length: Int = repr.length def apply(index: Int): T = repr(index) diff --git a/src/library/scala/collection/mutable/ArrayStack.scala b/src/library/scala/collection/mutable/ArrayStack.scala index f5287312b9..b3a0534826 100644 --- a/src/library/scala/collection/mutable/ArrayStack.scala +++ b/src/library/scala/collection/mutable/ArrayStack.scala @@ -21,7 +21,7 @@ object ArrayStack extends SeqFactory[ArrayStack] { implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArrayStack[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]] def newBuilder[A]: Builder[A, ArrayStack[A]] = new ArrayStack[A] def empty: ArrayStack[Nothing] = new ArrayStack() - def apply[A: ClassManifest](elems: A*): ArrayStack[A] = { + def apply[A: ArrayTag](elems: A*): ArrayStack[A] = { val els: Array[AnyRef] = elems.reverseMap(_.asInstanceOf[AnyRef])(breakOut) if (els.length == 0) new ArrayStack() else new ArrayStack[A](els, els.length) diff --git a/src/library/scala/collection/mutable/FlatArray.scala b/src/library/scala/collection/mutable/FlatArray.scala index 3e43b66ecf..5b4b5e777f 100644 --- a/src/library/scala/collection/mutable/FlatArray.scala +++ b/src/library/scala/collection/mutable/FlatArray.scala @@ -11,7 +11,7 @@ package scala.collection package mutable -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag import generic.CanBuildFrom /** @@ -62,16 +62,16 @@ object FlatArray { def ofDim[Boxed, Unboxed](size:Int) (implicit boxings: BoxingConversions[Boxed, Unboxed], - manifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { + tag: ArrayTag[Unboxed]): FlatArray[Boxed] = { val elems = Array.ofDim[Unboxed](size) - new FlatArray.Impl(elems, boxings, manifest) + new FlatArray.Impl(elems, boxings, tag) } def empty[Boxed, Unboxed](implicit boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = apply() + elemTag: ArrayTag[Unboxed]): FlatArray[Boxed] = apply() def apply[Boxed, Unboxed](elems: Boxed*) - (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): FlatArray[Boxed] = { + (implicit boxings: BoxingConversions[Boxed, Unboxed], elemTag: ArrayTag[Unboxed]): FlatArray[Boxed] = { val b = newBuilder[Boxed, Unboxed] b.sizeHint(elems.length) b ++= elems @@ -79,13 +79,13 @@ object FlatArray { } def newBuilder[Boxed, Unboxed] - (implicit boxings: BoxingConversions[Boxed, Unboxed], elemManifest: ClassManifest[Unboxed]): Builder[Boxed, FlatArray[Boxed]] = - new Bldr[Boxed, Unboxed](boxings, elemManifest) + (implicit boxings: BoxingConversions[Boxed, Unboxed], elemTag: ArrayTag[Unboxed]): Builder[Boxed, FlatArray[Boxed]] = + new Bldr[Boxed, Unboxed](boxings, elemTag) implicit def canBuildFrom[Boxed, Unboxed]( implicit boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]): CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] = + elemTag: ArrayTag[Unboxed]): CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] = new CanBuildFrom[FlatArray[_], Boxed, FlatArray[Boxed]] { def apply(from: FlatArray[_]): Builder[Boxed, FlatArray[Boxed]] = newBuilder[Boxed, Unboxed] @@ -93,14 +93,14 @@ object FlatArray { newBuilder[Boxed, Unboxed] } - private class Bldr[Boxed, Unboxed](boxings: BoxingConversions[Boxed, Unboxed], manifest: ClassManifest[Unboxed]) extends Builder[Boxed, FlatArray[Boxed]] { + private class Bldr[Boxed, Unboxed](boxings: BoxingConversions[Boxed, Unboxed], tag: ArrayTag[Unboxed]) extends Builder[Boxed, FlatArray[Boxed]] { private var elems: Array[Unboxed] = _ private var capacity: Int = 0 private var size: Int = 0 private def resize(size: Int) { - val newelems = manifest.newArray(size) + val newelems = tag.newArray(size) if (this.size > 0) Array.copy(elems, 0, newelems, 0, this.size) elems = newelems capacity = size @@ -131,14 +131,14 @@ object FlatArray { def result(): FlatArray[Boxed] = { if (capacity == 0 || capacity != size) resize(size) - new FlatArray.Impl(elems, boxings, manifest) + new FlatArray.Impl(elems, boxings, tag) } } private class Impl[Boxed, Unboxed]( elems: Array[Unboxed], boxings: BoxingConversions[Boxed, Unboxed], - elemManifest: ClassManifest[Unboxed]) extends FlatArray[Boxed] { + elemTag: ArrayTag[Unboxed]) extends FlatArray[Boxed] { def length = elems.length @@ -149,9 +149,9 @@ object FlatArray { /** Creates new builder for this collection ==> move to subclasses */ override protected[this] def newBuilder: Builder[Boxed, FlatArray[Boxed]] = - new Bldr[Boxed, Unboxed](boxings, elemManifest) + new Bldr[Boxed, Unboxed](boxings, elemTag) /** Clones this object, including the underlying Array. */ - override def clone: FlatArray[Boxed] = new Impl[Boxed, Unboxed](elems.clone(), boxings, elemManifest) + override def clone: FlatArray[Boxed] = new Impl[Boxed, Unboxed](elems.clone(), boxings, elemTag) } } diff --git a/src/library/scala/collection/mutable/UnrolledBuffer.scala b/src/library/scala/collection/mutable/UnrolledBuffer.scala index 09e6088782..889768d471 100644 --- a/src/library/scala/collection/mutable/UnrolledBuffer.scala +++ b/src/library/scala/collection/mutable/UnrolledBuffer.scala @@ -41,11 +41,11 @@ import annotation.tailrec * */ @SerialVersionUID(1L) -class UnrolledBuffer[T](implicit val manifest: ClassManifest[T]) +class UnrolledBuffer[T](implicit val tag: ArrayTag[T]) extends collection.mutable.AbstractBuffer[T] with collection.mutable.Buffer[T] with collection.mutable.BufferLike[T, UnrolledBuffer[T]] - with GenericClassManifestTraversableTemplate[T, UnrolledBuffer] + with GenericArrayTagTraversableTemplate[T, UnrolledBuffer] with collection.mutable.Builder[T, UnrolledBuffer[T]] with Serializable { @@ -67,7 +67,7 @@ extends collection.mutable.AbstractBuffer[T] private[collection] def calcNextLength(sz: Int) = sz - def classManifestCompanion = UnrolledBuffer + def arrayTagCompanion = UnrolledBuffer /** Concatenates the targer unrolled buffer to this unrolled buffer. * @@ -183,11 +183,11 @@ extends collection.mutable.AbstractBuffer[T] } -object UnrolledBuffer extends ClassManifestTraversableFactory[UnrolledBuffer] { +object UnrolledBuffer extends ArrayTagTraversableFactory[UnrolledBuffer] { /** $genericCanBuildFromInfo */ - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = + implicit def canBuildFrom[T](implicit t: ArrayTag[T]): CanBuildFrom[Coll, T, UnrolledBuffer[T]] = new GenericCanBuildFrom[T] - def newBuilder[T](implicit m: ClassManifest[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] + def newBuilder[T](implicit t: ArrayTag[T]): Builder[T, UnrolledBuffer[T]] = new UnrolledBuffer[T] val waterline = 50 val waterlineDelim = 100 @@ -195,7 +195,7 @@ object UnrolledBuffer extends ClassManifestTraversableFactory[UnrolledBuffer] { /** Unrolled buffer node. */ - class Unrolled[T: ClassManifest] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { + class Unrolled[T: ArrayTag] private[collection] (var size: Int, var array: Array[T], var next: Unrolled[T], val buff: UnrolledBuffer[T] = null) { private[collection] def this() = this(0, new Array[T](unrolledlength), null, null) private[collection] def this(b: UnrolledBuffer[T]) = this(0, new Array[T](unrolledlength), null, b) diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala index fac4eb77bb..5e20f4ec61 100644 --- a/src/library/scala/collection/mutable/WrappedArray.scala +++ b/src/library/scala/collection/mutable/WrappedArray.scala @@ -11,7 +11,8 @@ package scala.collection package mutable -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ import scala.collection.generic._ import scala.collection.parallel.mutable.ParArray @@ -40,8 +41,11 @@ extends AbstractSeq[T] override protected[this] def thisCollection: WrappedArray[T] = this override protected[this] def toCollection(repr: WrappedArray[T]): WrappedArray[T] = repr - /** The manifest of the element type */ - def elemManifest: ClassManifest[T] + /** The tag of the element type */ + def elemTag: ArrayTag[T] + + @deprecated("use elemTag instead", "2.10.0") + def elemManifest: ClassManifest[T] = ClassManifest[T](arrayElementClass(elemTag)) /** The length of the array */ def length: Int @@ -57,11 +61,16 @@ extends AbstractSeq[T] override def par = ParArray.handoff(array) - override def toArray[U >: T : ClassManifest]: Array[U] = - if (implicitly[ClassManifest[U]].erasure eq array.getClass.getComponentType) + private def elementClass: Class[_] = + arrayElementClass(repr.getClass) + + override def toArray[U >: T : ArrayTag]: Array[U] = { + val thatElementClass = arrayElementClass(implicitly[ArrayTag[U]]) + if (elementClass eq thatElementClass) array.asInstanceOf[Array[U]] else super.toArray[U] + } override def stringPrefix = "WrappedArray" @@ -71,7 +80,7 @@ extends AbstractSeq[T] /** Creates new builder for this collection ==> move to subclasses */ override protected[this] def newBuilder: Builder[T, WrappedArray[T]] = - new WrappedArrayBuilder[T](elemManifest) + new WrappedArrayBuilder[T](elemTag) } @@ -101,7 +110,7 @@ object WrappedArray { case x: Array[Unit] => new ofUnit(x) }).asInstanceOf[WrappedArray[T]] - implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = + implicit def canBuildFrom[T](implicit m: ArrayTag[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = new CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] { def apply(from: WrappedArray[_]): Builder[T, WrappedArray[T]] = ArrayBuilder.make[T]()(m) mapResult WrappedArray.make[T] @@ -112,70 +121,70 @@ object WrappedArray { def newBuilder[A]: Builder[A, IndexedSeq[A]] = new ArrayBuffer final class ofRef[T <: AnyRef](val array: Array[T]) extends WrappedArray[T] with Serializable { - lazy val elemManifest = ClassManifest[T](array.getClass.getComponentType) + lazy val elemTag = ClassTag[T](arrayElementClass(array.getClass)) def length: Int = array.length def apply(index: Int): T = array(index).asInstanceOf[T] def update(index: Int, elem: T) { array(index) = elem } } final class ofByte(val array: Array[Byte]) extends WrappedArray[Byte] with Serializable { - def elemManifest = ClassManifest.Byte + def elemTag = ClassTag.Byte def length: Int = array.length def apply(index: Int): Byte = array(index) def update(index: Int, elem: Byte) { array(index) = elem } } final class ofShort(val array: Array[Short]) extends WrappedArray[Short] with Serializable { - def elemManifest = ClassManifest.Short + def elemTag = ClassTag.Short def length: Int = array.length def apply(index: Int): Short = array(index) def update(index: Int, elem: Short) { array(index) = elem } } final class ofChar(val array: Array[Char]) extends WrappedArray[Char] with Serializable { - def elemManifest = ClassManifest.Char + def elemTag = ClassTag.Char def length: Int = array.length def apply(index: Int): Char = array(index) def update(index: Int, elem: Char) { array(index) = elem } } final class ofInt(val array: Array[Int]) extends WrappedArray[Int] with Serializable { - def elemManifest = ClassManifest.Int + def elemTag = ClassTag.Int def length: Int = array.length def apply(index: Int): Int = array(index) def update(index: Int, elem: Int) { array(index) = elem } } final class ofLong(val array: Array[Long]) extends WrappedArray[Long] with Serializable { - def elemManifest = ClassManifest.Long + def elemTag = ClassTag.Long def length: Int = array.length def apply(index: Int): Long = array(index) def update(index: Int, elem: Long) { array(index) = elem } } final class ofFloat(val array: Array[Float]) extends WrappedArray[Float] with Serializable { - def elemManifest = ClassManifest.Float + def elemTag = ClassTag.Float def length: Int = array.length def apply(index: Int): Float = array(index) def update(index: Int, elem: Float) { array(index) = elem } } final class ofDouble(val array: Array[Double]) extends WrappedArray[Double] with Serializable { - def elemManifest = ClassManifest.Double + def elemTag = ClassTag.Double def length: Int = array.length def apply(index: Int): Double = array(index) def update(index: Int, elem: Double) { array(index) = elem } } final class ofBoolean(val array: Array[Boolean]) extends WrappedArray[Boolean] with Serializable { - def elemManifest = ClassManifest.Boolean + def elemTag = ClassTag.Boolean def length: Int = array.length def apply(index: Int): Boolean = array(index) def update(index: Int, elem: Boolean) { array(index) = elem } } final class ofUnit(val array: Array[Unit]) extends WrappedArray[Unit] with Serializable { - def elemManifest = ClassManifest.Unit + def elemTag = ClassTag.Unit def length: Int = array.length def apply(index: Int): Unit = array(index) def update(index: Int, elem: Unit) { array(index) = elem } diff --git a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala index fce65468e9..99a0b0ede3 100644 --- a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala +++ b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala @@ -12,23 +12,27 @@ package scala.collection package mutable import generic._ -import scala.reflect.ClassManifest +import scala.reflect.ArrayTag +import scala.runtime.ScalaRunTime._ /** A builder class for arrays. * - * @tparam A type of elements that can be added to this builder. - * @param manifest class manifest for objects of type `A`. + * @tparam A type of elements that can be added to this builder. + * @param tag class tag for objects of type `A`. * * @since 2.8 */ -class WrappedArrayBuilder[A](manifest: ClassManifest[A]) extends Builder[A, WrappedArray[A]] { +class WrappedArrayBuilder[A](tag: ArrayTag[A]) extends Builder[A, WrappedArray[A]] { + + @deprecated("use tag instead", "2.10.0") + val manifest: ArrayTag[A] = tag private var elems: WrappedArray[A] = _ private var capacity: Int = 0 private var size: Int = 0 private def mkArray(size: Int): WrappedArray[A] = { - val erasure = manifest.erasure + val erasure = arrayElementClass(tag) val newelems = erasure match { case java.lang.Byte.TYPE => new WrappedArray.ofByte(new Array[Byte](size)).asInstanceOf[WrappedArray[A]] case java.lang.Short.TYPE => new WrappedArray.ofShort(new Array[Short](size)).asInstanceOf[WrappedArray[A]] @@ -39,7 +43,7 @@ class WrappedArrayBuilder[A](manifest: ClassManifest[A]) extends Builder[A, Wrap case java.lang.Double.TYPE => new WrappedArray.ofDouble(new Array[Double](size)).asInstanceOf[WrappedArray[A]] case java.lang.Boolean.TYPE => new WrappedArray.ofBoolean(new Array[Boolean](size)).asInstanceOf[WrappedArray[A]] case java.lang.Void.TYPE => new WrappedArray.ofUnit(new Array[Unit](size)).asInstanceOf[WrappedArray[A]] - case _ => new WrappedArray.ofRef[A with AnyRef](manifest.newArray(size).asInstanceOf[Array[A with AnyRef]]).asInstanceOf[WrappedArray[A]] + case _ => new WrappedArray.ofRef[A with AnyRef](tag.newArray(size).asInstanceOf[Array[A with AnyRef]]).asInstanceOf[WrappedArray[A]] } if (this.size > 0) Array.copy(elems.array, 0, newelems.array, 0, this.size) newelems diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 5bf338f560..014b9b1a42 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -155,15 +155,15 @@ extends GenIterableLike[T, Repr] with HasNewCombiner[T, Repr] { self: ParIterableLike[T, Repr, Sequential] => - + @transient @volatile private var _tasksupport = defaultTaskSupport - + protected def initTaskSupport() { _tasksupport = defaultTaskSupport } - + def tasksupport = { val ts = _tasksupport if (ts eq null) { @@ -171,9 +171,9 @@ self: ParIterableLike[T, Repr, Sequential] => defaultTaskSupport } else ts } - + def tasksupport_=(ts: TaskSupport) = _tasksupport = ts - + def seq: Sequential def repr: Repr = this.asInstanceOf[Repr] @@ -240,7 +240,7 @@ self: ParIterableLike[T, Repr, Sequential] => trait BuilderOps[Elem, To] { trait Otherwise[Cmb] { - def otherwise(notbody: => Unit)(implicit m: ClassManifest[Cmb]): Unit + def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]): Unit } def ifIs[Cmb](isbody: Cmb => Unit): Otherwise[Cmb] @@ -282,8 +282,8 @@ self: ParIterableLike[T, Repr, Sequential] => protected implicit def builder2ops[Elem, To](cb: Builder[Elem, To]) = new BuilderOps[Elem, To] { def ifIs[Cmb](isbody: Cmb => Unit) = new Otherwise[Cmb] { - def otherwise(notbody: => Unit)(implicit m: ClassManifest[Cmb]) { - if (cb.getClass == m.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody + def otherwise(notbody: => Unit)(implicit t: ClassTag[Cmb]) { + if (cb.getClass == t.erasure) isbody(cb.asInstanceOf[Cmb]) else notbody } } def isCombiner = cb.isInstanceOf[Combiner[_, _]] @@ -754,7 +754,7 @@ self: ParIterableLike[T, Repr, Sequential] => cntx.setIndexFlag(Int.MaxValue) tasksupport.executeAndWaitResult( new Span(0, pred, combinerFactory, combinerFactory, splitter assign cntx) mapResult { - _._2.resultWithTaskSupport + _._2.resultWithTaskSupport } ) } @@ -802,7 +802,7 @@ self: ParIterableLike[T, Repr, Sequential] => def size = splitter.remaining } - override def toArray[U >: T: ClassManifest]: Array[U] = { + override def toArray[U >: T: ArrayTag]: Array[U] = { val arr = new Array[U](size) copyToArray(arr) arr diff --git a/src/library/scala/collection/parallel/mutable/ParArray.scala b/src/library/scala/collection/parallel/mutable/ParArray.scala index 8cc0b95997..92ba701f7c 100644 --- a/src/library/scala/collection/parallel/mutable/ParArray.scala +++ b/src/library/scala/collection/parallel/mutable/ParArray.scala @@ -676,7 +676,7 @@ self => private def readObject(in: java.io.ObjectInputStream) { in.defaultReadObject - + // get raw array from arrayseq array = arrayseq.array.asInstanceOf[Array[Any]] } @@ -706,7 +706,7 @@ object ParArray extends ParFactory[ParArray] { case _ => new ParArray[T](new ExposedArraySeq[T](runtime.ScalaRunTime.toObjectArray(arr), sz)) } - def createFromCopy[T <: AnyRef : ClassManifest](arr: Array[T]): ParArray[T] = { + def createFromCopy[T <: AnyRef : ArrayTag](arr: Array[T]): ParArray[T] = { val newarr = new Array[T](arr.length) Array.copy(arr, 0, newarr, 0, arr.length) handoff(newarr) diff --git a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala index 410b542a68..43d40776bf 100644 --- a/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala +++ b/src/library/scala/collection/parallel/mutable/UnrolledParArrayCombiner.scala @@ -26,7 +26,7 @@ import scala.collection.parallel.Task -private[mutable] class DoublingUnrolledBuffer[T](implicit m: ClassManifest[T]) extends UnrolledBuffer[T]()(m) { +private[mutable] class DoublingUnrolledBuffer[T](implicit t: ArrayTag[T]) extends UnrolledBuffer[T]()(t) { override def calcNextLength(sz: Int) = if (sz < 10000) sz * 2 else sz protected override def newUnrolled = new Unrolled[T](0, new Array[T](4), null, this) } diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 9aaf05dbd6..def086bc03 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -134,26 +134,26 @@ trait Future[+T] extends Awaitable[T] { /** Creates a new promise. */ protected def newPromise[S]: Promise[S] - + /** Returns whether the future has already been completed with * a value or an exception. - * + * * $nonDeterministic - * + * * @return `true` if the future is already completed, `false` otherwise */ def isCompleted: Boolean - + /** The value of this `Future`. - * + * * If the future is not completed the returned value will be `None`. * If the future is completed the value will be `Some(Success(t))` * if it contains a valid result, or `Some(Failure(error))` if it contains * an exception. */ def value: Option[Either[Throwable, T]] - - + + /* Projections */ /** Returns a failed projection of this future. @@ -421,11 +421,11 @@ trait Future[+T] extends Awaitable[T] { } p.future } - + /** Creates a new `Future[S]` which is completed with this `Future`'s result if * that conforms to `S`'s erased type or a `ClassCastException` otherwise. */ - def mapTo[S](implicit m: Manifest[S]): Future[S] = { + def mapTo[S](implicit tag: ClassTag[S]): Future[S] = { import java.{ lang => jl } val toBoxed = Map[Class[_], Class[_]]( classOf[Boolean] -> classOf[jl.Boolean], @@ -444,20 +444,20 @@ trait Future[+T] extends Awaitable[T] { } val p = newPromise[S] - + onComplete { case l: Left[Throwable, _] => p complete l.asInstanceOf[Either[Throwable, S]] case Right(t) => p complete (try { - Right(boxedType(m.erasure).cast(t).asInstanceOf[S]) + Right(boxedType(tag.erasure).cast(t).asInstanceOf[S]) } catch { case e: ClassCastException => Left(e) }) } - + p.future } - + /** Applies the side-effecting function to the result of this future, and returns * a new future with the result of this future. * @@ -591,7 +591,7 @@ object Future { * The fold is performed on the thread where the last future is completed, * the result will be the first failure of any of the futures, or any failure in the actual fold, * or the result of the fold. - * + * * Example: * {{{ * val result = Await.result(Future.fold(futures)(0)(_ + _), 5 seconds) @@ -603,7 +603,7 @@ object Future { } /** Initiates a fold over the supplied futures where the fold-zero is the result value of the `Future` that's completed first. - * + * * Example: * {{{ * val result = Await.result(Futures.reduce(futures)(_ + _), 5 seconds) @@ -613,11 +613,11 @@ object Future { if (futures.isEmpty) Promise[R].failure(new NoSuchElementException("reduce attempted on empty collection")).future else sequence(futures).map(_ reduceLeft op) } - + /** Transforms a `Traversable[A]` into a `Future[Traversable[B]]` using the provided function `A => Future[B]`. * This is useful for performing a parallel map. For example, to apply a function to all items of a list * in parallel: - * + * * {{{ * val myFutureList = Future.traverse(myList)(x => Future(myFunc(x))) * }}} @@ -627,7 +627,7 @@ object Future { val fb = fn(a.asInstanceOf[A]) for (r <- fr; b <- fb) yield (r += b) }.map(_.result) - + } diff --git a/src/library/scala/reflect/DummyMirror.scala b/src/library/scala/reflect/DummyMirror.scala index 8b2ddde2a1..276237fce4 100644 --- a/src/library/scala/reflect/DummyMirror.scala +++ b/src/library/scala/reflect/DummyMirror.scala @@ -5,9 +5,10 @@ import scala.reflect.api.Attachment import scala.reflect.api.Modifier import scala.reflect.api.Universe +// todo. make Dummy objects not equal to themselves class DummyMirror(cl: ClassLoader) extends api.Mirror { // Members declared in scala.reflect.api.AnnotationInfos - implicit def classfileAnnotArgManifest: scala.reflect.ClassManifest[ClassfileAnnotArg] = notSupported() + implicit def classfileAnnotArgTag: scala.reflect.ClassTag[ClassfileAnnotArg] = notSupported() type AnnotationInfo = DummyAnnotationInfo.type object DummyAnnotationInfo val AnnotationInfo: AnnotationInfoExtractor = DummyAnnotationInfoExtractor diff --git a/src/library/scala/reflect/api/AnnotationInfos.scala b/src/library/scala/reflect/api/AnnotationInfos.scala index 96a65606e5..cc1c4d2b6b 100755 --- a/src/library/scala/reflect/api/AnnotationInfos.scala +++ b/src/library/scala/reflect/api/AnnotationInfos.scala @@ -12,7 +12,7 @@ trait AnnotationInfos { self: Universe => } type ClassfileAnnotArg <: AnyRef - implicit def classfileAnnotArgManifest: ClassManifest[ClassfileAnnotArg] // need a precise manifest to pass to UnPickle's toArray call + implicit def classfileAnnotArgTag: ArrayTag[ClassfileAnnotArg] // need a precise tag to pass to UnPickle's toArray call type LiteralAnnotArg <: ClassfileAnnotArg val LiteralAnnotArg: LiteralAnnotArgExtractor diff --git a/src/library/scala/util/Marshal.scala b/src/library/scala/util/Marshal.scala index 6eb58e8570..e2ebe7851c 100644 --- a/src/library/scala/util/Marshal.scala +++ b/src/library/scala/util/Marshal.scala @@ -48,4 +48,4 @@ object Marshal { "\n required: "+expected) } } -}
\ No newline at end of file +} diff --git a/src/library/scala/util/Sorting.scala b/src/library/scala/util/Sorting.scala index bf460a118f..7d98e57741 100644 --- a/src/library/scala/util/Sorting.scala +++ b/src/library/scala/util/Sorting.scala @@ -8,7 +8,7 @@ package scala.util -import scala.reflect.ClassManifest +import scala.reflect.ClassTag import scala.math.Ordering /** The Sorting object provides functions that can sort various kinds of @@ -39,14 +39,14 @@ object Sorting { /** Sort an array of K where K is Ordered, preserving the existing order * where the values are equal. */ - def stableSort[K: ClassManifest: Ordering](a: Array[K]) { + def stableSort[K: ArrayTag: Ordering](a: Array[K]) { stableSort(a, 0, a.length-1, new Array[K](a.length), Ordering[K].lt _) } /** Sorts an array of `K` given an ordering function `f`. * `f` should return `true` iff its first parameter is strictly less than its second parameter. */ - def stableSort[K: ClassManifest](a: Array[K], f: (K, K) => Boolean) { + def stableSort[K: ArrayTag](a: Array[K], f: (K, K) => Boolean) { stableSort(a, 0, a.length-1, new Array[K](a.length), f) } @@ -57,14 +57,14 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ClassManifest](a: Seq[K], f: (K, K) => Boolean): Array[K] = { + def stableSort[K: ArrayTag](a: Seq[K], f: (K, K) => Boolean): Array[K] = { val ret = a.toArray stableSort(ret, f) ret } /** Sorts an arbitrary sequence of items that are viewable as ordered. */ - def stableSort[K: ClassManifest: Ordering](a: Seq[K]): Array[K] = + def stableSort[K: ArrayTag: Ordering](a: Seq[K]): Array[K] = stableSort(a, Ordering[K].lt _) /** Stably sorts a sequence of items given an extraction function that will @@ -74,8 +74,8 @@ object Sorting { * @param f the comparison function. * @return the sorted sequence of items. */ - def stableSort[K: ClassManifest, M: Ordering](a: Seq[K], f: K => M): Array[K] = - stableSort(a)(implicitly[ClassManifest[K]], Ordering[M] on f) + def stableSort[K: ArrayTag, M: Ordering](a: Seq[K], f: K => M): Array[K] = + stableSort(a)(implicitly[ArrayTag[K]], Ordering[M] on f) private def sort1[K: Ordering](x: Array[K], off: Int, len: Int) { val ord = Ordering[K] @@ -498,7 +498,7 @@ object Sorting { sort2(off, len) } - private def stableSort[K : ClassManifest](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { + private def stableSort[K : ArrayTag](a: Array[K], lo: Int, hi: Int, scratch: Array[K], f: (K,K) => Boolean) { if (lo < hi) { val mid = (lo+hi) / 2 stableSort(a, lo, mid, scratch, f) diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala index 1cae8088f5..38f4abb20a 100644 --- a/src/library/scala/util/control/Exception.scala +++ b/src/library/scala/util/control/Exception.scala @@ -30,9 +30,9 @@ import language.implicitConversions object Exception { type Catcher[+T] = PartialFunction[Throwable, T] - def mkCatcher[Ex <: Throwable: ClassManifest, T](isDef: Ex => Boolean, f: Ex => T) = new Catcher[T] { + def mkCatcher[Ex <: Throwable: ClassTag, T](isDef: Ex => Boolean, f: Ex => T) = new Catcher[T] { private def downcast(x: Throwable): Option[Ex] = - if (classManifest[Ex].erasure.isAssignableFrom(x.getClass)) Some(x.asInstanceOf[Ex]) + if (classTag[Ex].erasure.isAssignableFrom(x.getClass)) Some(x.asInstanceOf[Ex]) else None def isDefinedAt(x: Throwable) = downcast(x) exists isDef @@ -41,7 +41,7 @@ object Exception { def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T) = mkCatcher(isDef, f) - implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassManifest, T](pf: PartialFunction[Ex, T]) = + implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassTag, T](pf: PartialFunction[Ex, T]) = mkCatcher(pf.isDefinedAt _, pf.apply _) /** !!! Not at all sure of every factor which goes into this, |