summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library/scala/collection/SeqView.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayOps.scala6
-rw-r--r--src/library/scala/collection/mutable/IndexedSeqView.scala23
-rw-r--r--src/library/scala/collection/mutable/WrappedArray.scala7
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala3
-rw-r--r--test/files/run/colltest1.check8
-rw-r--r--test/files/run/t2074_2.check6
-rw-r--r--test/files/run/t2074_2.scala5
-rw-r--r--test/files/run/viewtest.check12
-rwxr-xr-xtest/files/run/viewtest.scala2
10 files changed, 49 insertions, 25 deletions
diff --git a/src/library/scala/collection/SeqView.scala b/src/library/scala/collection/SeqView.scala
index 61443b3b90..79d50f1de6 100644
--- a/src/library/scala/collection/SeqView.scala
+++ b/src/library/scala/collection/SeqView.scala
@@ -21,6 +21,8 @@ import TraversableView.NoBuilder
*/
trait SeqView[+A, +Coll] extends SeqViewLike[A, Coll, SeqView[A, Coll]]
+/** $factoryInfo
+ */
object SeqView {
type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]}
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, SeqView[A, Seq[_]]] =
diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala
index 61fcc77e14..553461c805 100644
--- a/src/library/scala/collection/mutable/ArrayOps.scala
+++ b/src/library/scala/collection/mutable/ArrayOps.scala
@@ -24,6 +24,12 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] {
ClassManifest.fromClass(
repr.getClass.getComponentType.getComponentType.asInstanceOf[Predef.Class[U]]))
+ override def toArray[U >: T : ClassManifest]: Array[U] =
+ if (implicitly[ClassManifest[U]].erasure eq repr.getClass.getComponentType)
+ repr.asInstanceOf[Array[U]]
+ else
+ super.toArray[U]
+
/** Flattens a two-dimensional array by concatenating all its rows
* into a single array
*/
diff --git a/src/library/scala/collection/mutable/IndexedSeqView.scala b/src/library/scala/collection/mutable/IndexedSeqView.scala
index c6c92db1e7..d870b762d3 100644
--- a/src/library/scala/collection/mutable/IndexedSeqView.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqView.scala
@@ -91,9 +91,22 @@ self =>
override def reverse: IndexedSeqView[A, Coll] = newReversed.asInstanceOf[IndexedSeqView[A, Coll]]
}
-/*
- * object IndexedSeqView {
- type Coll = TraversableView[_, C] forSome { type C <: scala.collection.Traversable[_] }
- implicit def canBuildFrom[A]: CanBuildFrom[IndexedSeq[_], A, IndexedSeqView[A], Coll] = new CanBuildFrom[mutable.IndexedSeq[_], A, IndexedSeqView[A], Coll] { : Coll) = new NoBuilder }
+/** $factoryInfo
+ * Note that the canBuildFrom factories yield SeqViews, not IndexedSewqViews.
+ * This is intentional, because not all operations yield again a mutable.IndexedSeqView.
+ * For instance, map just gives a SeqView, which reflects the fact that
+ * map cannot do its work and maintain a pointer into the original indexed sequence.
+ */
+object IndexedSeqView {
+ type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]}
+ implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, SeqView[A, Seq[_]]] =
+ new CanBuildFrom[Coll, A, SeqView[A, Seq[_]]] {
+ def apply(from: Coll) = new NoBuilder
+ def apply() = new NoBuilder
+ }
+ implicit def arrCanBuildFrom[A]: CanBuildFrom[TraversableView[_, Array[_]], A, SeqView[A, Array[A]]] =
+ new CanBuildFrom[TraversableView[_, Array[_]], A, SeqView[A, Array[A]]] {
+ def apply(from: TraversableView[_, Array[_]]) = new NoBuilder
+ def apply() = new NoBuilder
+ }
}
-*/
diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala
index 6652f5e40a..10117a1086 100644
--- a/src/library/scala/collection/mutable/WrappedArray.scala
+++ b/src/library/scala/collection/mutable/WrappedArray.scala
@@ -41,6 +41,13 @@ abstract class WrappedArray[T] extends IndexedSeq[T] with ArrayLike[T, WrappedAr
/** The underlying array */
def array: Array[T]
+
+ override def toArray[U >: T : ClassManifest]: Array[U] =
+ if (implicitly[ClassManifest[U]].erasure eq array.getClass.getComponentType)
+ array.asInstanceOf[Array[U]]
+ else
+ super.toArray[U]
+
override def stringPrefix = "WrappedArray"
/** Clones this object, including the underlying Array. */
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 2970cf1980..dffebfc892 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -12,7 +12,7 @@
package scala.runtime
import scala.reflect.ClassManifest
-import scala.collection.{ Seq, IndexedSeq }
+import scala.collection.{ Seq, IndexedSeq, TraversableView }
import scala.collection.mutable.WrappedArray
import scala.collection.immutable.{ List, Stream, Nil, :: }
import scala.xml.{ Node, MetaData }
@@ -240,6 +240,7 @@ object ScalaRunTime {
// Not to mention MetaData extends Iterable[MetaData]
case x: MetaData => x toString
case x: AnyRef if isArray(x) => WrappedArray make x map inner mkString ("Array(", ", ", ")")
+ case x: TraversableView[_, _] => x.toString
case x: Traversable[_] if !x.hasDefiniteSize => x.toString
case x: Traversable[_] =>
// Some subclasses of AbstractFile implement Iterable, then throw an
diff --git a/test/files/run/colltest1.check b/test/files/run/colltest1.check
index a5f4ada7a3..7377174281 100644
--- a/test/files/run/colltest1.check
+++ b/test/files/run/colltest1.check
@@ -72,11 +72,11 @@ new test starting with List()
9: List(2, 3, 4, 5, 6, 7, 8, 9, 10)
1
List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
-new test starting with IndexedSeq()
-10: IndexedSeq(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
-9: IndexedSeq(2, 3, 4, 5, 6, 7, 8, 9, 10)
+new test starting with Vector()
+10: Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+9: Vector(2, 3, 4, 5, 6, 7, 8, 9, 10)
1
-IndexedSeq(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
new test starting with Vector()
10: Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
9: Vector(2, 3, 4, 5, 6, 7, 8, 9, 10)
diff --git a/test/files/run/t2074_2.check b/test/files/run/t2074_2.check
index eb1f072de3..e4fc89b1ce 100644
--- a/test/files/run/t2074_2.check
+++ b/test/files/run/t2074_2.check
@@ -1,3 +1,3 @@
-IndexedSeqView(1, 2, 3)
-IndexedSeqView(1, 2, 3)
-IndexedSeqViewZ((1,1), (2,2), (3,3))
+SeqView(1, 2, 3)
+SeqView(1, 2, 3)
+SeqViewZ(...)
diff --git a/test/files/run/t2074_2.scala b/test/files/run/t2074_2.scala
index 4999552cc4..4624170f89 100644
--- a/test/files/run/t2074_2.scala
+++ b/test/files/run/t2074_2.scala
@@ -1,14 +1,15 @@
// replaced all occurrences of 'Vector' with 'IndexedSeq'
import scala.collection.immutable.IndexedSeq
-import scala.collection.IndexedSeqView
+import scala.collection.SeqView
object Test {
val funWithCCE = List.range(1,11).view.patch(5, List(100,101), 2)
- val v = new IndexedSeqView[Int, IndexedSeq[Int]] {
+ val v = new SeqView[Int, IndexedSeq[Int]] {
def underlying = IndexedSeq(1,2,3)
def apply(idx: Int) = underlying(idx)
def length = underlying.length
+ def iterator = underlying.iterator
}
val w = IndexedSeq(1, 2, 3).view
diff --git a/test/files/run/viewtest.check b/test/files/run/viewtest.check
index ded3ac0e92..6e0fe81a67 100644
--- a/test/files/run/viewtest.check
+++ b/test/files/run/viewtest.check
@@ -1,17 +1,11 @@
-SeqViewZ((x,0))
+SeqViewZ(...)
ys defined
mapping 1
2
-mapping 1
-mapping 2
-mapping 3
-SeqViewMS(3, 4)
+SeqViewMS(...)
mapping 3
4
-mapping 1
-mapping 2
-mapping 3
-SeqViewM(2, 3, 4)
+SeqViewM(...)
mapping 1
mapping 2
mapping 3
diff --git a/test/files/run/viewtest.scala b/test/files/run/viewtest.scala
index 280ded57cf..833c0101e3 100755
--- a/test/files/run/viewtest.scala
+++ b/test/files/run/viewtest.scala
@@ -13,7 +13,7 @@ object Test extends Application {
println(ys.force)
val zs = Array(1, 2, 3).view
- val as: IndexedSeqView[Int, Array[Int]] = zs map (_ + 1)
+ val as: SeqView[Int, Array[Int]] = zs map (_ + 1)
val bs: Array[Int] = as.force
val cs = zs.reverse
cs(0) += 1