summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-23 21:16:58 +0000
committerPaul Phillips <paulp@improving.org>2011-08-23 21:16:58 +0000
commit6ffea90982464bcbd08c5f4df55a0408215f7353 (patch)
tree1f5f8f6af71d5b99eaec2256864f10d46a89b6a7
parent71b458743e31f83372672e77bbbec1fab9c6550d (diff)
downloadscala-6ffea90982464bcbd08c5f4df55a0408215f7353.tar.gz
scala-6ffea90982464bcbd08c5f4df55a0408215f7353.tar.bz2
scala-6ffea90982464bcbd08c5f4df55a0408215f7353.zip
A conceivably pretty bad performance bug in bui...
A conceivably pretty bad performance bug in builders. SI-4821 pointed out that ArrayBuffer's ++ checks for a cheap size method by matching on IndexedSeq, but mutable.IndexedSeq, so all immutable collections are thrown in the same group as linear seqs. I went looking for other examples of this and found them, in key classes like Builder. The "type shadowing trap" is a serious issue in the collections. Closes SI-4821, no review.
-rw-r--r--src/library/scala/collection/mutable/ArrayBuffer.scala2
-rw-r--r--src/library/scala/collection/mutable/ArrayOps.scala2
-rw-r--r--src/library/scala/collection/mutable/Builder.scala4
3 files changed, 4 insertions, 4 deletions
diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala
index 7edbad6518..2b93138d8c 100644
--- a/src/library/scala/collection/mutable/ArrayBuffer.scala
+++ b/src/library/scala/collection/mutable/ArrayBuffer.scala
@@ -89,7 +89,7 @@ class ArrayBuffer[A](override protected val initialSize: Int)
* @return the updated buffer.
*/
override def ++=(xs: TraversableOnce[A]): this.type = xs match {
- case v: IndexedSeq[_] =>
+ case v: collection.IndexedSeqLike[_, _] =>
val n = v.length
ensureSize(size0 + n)
v.copyToArray(array.asInstanceOf[scala.Array[Any]], size0, n)
diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala
index 99929dd93c..008e7fab9a 100644
--- a/src/library/scala/collection/mutable/ArrayOps.scala
+++ b/src/library/scala/collection/mutable/ArrayOps.scala
@@ -65,7 +65,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza
*/
def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ClassManifest[U]): Array[U] = {
val b = Array.newBuilder[U]
- b.sizeHint(map{case is: IndexedSeq[_] => is.size case _ => 0} sum)
+ b.sizeHint(map{case is: collection.IndexedSeq[_] => is.size case _ => 0} sum)
for (xs <- this)
b ++= asTrav(xs)
b.result
diff --git a/src/library/scala/collection/mutable/Builder.scala b/src/library/scala/collection/mutable/Builder.scala
index 254820b726..44cc1c8582 100644
--- a/src/library/scala/collection/mutable/Builder.scala
+++ b/src/library/scala/collection/mutable/Builder.scala
@@ -65,7 +65,7 @@ trait Builder[-Elem, +To] extends Growable[Elem] {
* @param delta a correction to add to the `coll.size` to produce the size hint.
*/
def sizeHint(coll: TraversableLike[_, _], delta: Int = 0) {
- if (coll.isInstanceOf[IndexedSeqLike[_,_]]) {
+ if (coll.isInstanceOf[collection.IndexedSeqLike[_,_]]) {
sizeHint(coll.size + delta)
}
}
@@ -83,7 +83,7 @@ trait Builder[-Elem, +To] extends Growable[Elem] {
* than collection's size are reduced.
*/
def sizeHintBounded(size: Int, boundingColl: TraversableLike[_, _]) {
- if (boundingColl.isInstanceOf[IndexedSeqLike[_,_]])
+ if (boundingColl.isInstanceOf[collection.IndexedSeqLike[_,_]])
sizeHint(size min boundingColl.size)
}