diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-08-15 15:50:03 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-08-15 15:50:03 +0200 |
commit | 0308ae88026a4a8d427d1a9156c31c0ff8dd2561 (patch) | |
tree | 6b67fc0f55bf2b6d088f39a5fe8cc5efb636b89e /test/files/run/t6150.scala | |
parent | 3ccaa1026e7e74d99fe39c9608e28c48b422e2c9 (diff) | |
download | scala-0308ae88026a4a8d427d1a9156c31c0ff8dd2561.tar.gz scala-0308ae88026a4a8d427d1a9156c31c0ff8dd2561.tar.bz2 scala-0308ae88026a4a8d427d1a9156c31c0ff8dd2561.zip |
Fixes SI-6150.
Removes the `VectorReusableCBF` and pattern matching on it in optimized `Vector` methods.
Instead, we now have a new `ReusableCBF` instance in `IndexedSeq` and check for equality
when trying to optimize `:+`, `+:` and `updated`.
This overridden `ReusableCBF` is used by `IndexedSeq`, `immutable.IndexedSeq` and
`immutable.Vector`.
The net effect is that calling `:+` and similar methods on a `Vector` instance with
a `CBF` that came from `IndexedSeq` or somewhere lower in the hierarchy will always
create a `Vector` using the optimized method.
Diffstat (limited to 'test/files/run/t6150.scala')
-rw-r--r-- | test/files/run/t6150.scala | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/files/run/t6150.scala b/test/files/run/t6150.scala new file mode 100644 index 0000000000..1b3de0c50a --- /dev/null +++ b/test/files/run/t6150.scala @@ -0,0 +1,34 @@ + + + +import collection._ + + + +object Test extends App { + + val cbf1 = implicitly[generic.CanBuildFrom[Vector[Int], Int, IndexedSeq[Int]]] + val cbf2 = implicitly[generic.CanBuildFrom[immutable.IndexedSeq[Int], Int, IndexedSeq[Int]]] + val cbf3 = implicitly[generic.CanBuildFrom[IndexedSeq[Int], Int, IndexedSeq[Int]]] + + def check[C](v: C) = { + assert(v == Vector(1, 2, 3, 4)) + assert(v.isInstanceOf[Vector[_]]) + } + + val v = immutable.Vector(1, 2, 3) + + check(v.:+(4)(cbf1)) + check(v.:+(4)(cbf2)) + check(v.:+(4)(cbf3)) + + val iiv: immutable.IndexedSeq[Int] = immutable.Vector(1, 2, 3) + + check(iiv.:+(4)(cbf2)) + check(iiv.:+(4)(cbf3)) + + val iv: IndexedSeq[Int] = immutable.Vector(1, 2, 3) + + check(iv.:+(4)(cbf3)) + +} |