From 6ffea90982464bcbd08c5f4df55a0408215f7353 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 23 Aug 2011 21:16:58 +0000 Subject: 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. --- src/library/scala/collection/mutable/ArrayBuffer.scala | 2 +- src/library/scala/collection/mutable/ArrayOps.scala | 2 +- src/library/scala/collection/mutable/Builder.scala | 4 ++-- 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) } -- cgit v1.2.3