diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-15 20:46:35 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-15 20:46:35 +0000 |
commit | f309513c9f540e1e9eb5c072e66cb64333aa7bda (patch) | |
tree | 3b776b1cd64e9a428573be3aeddfd5e3f91f330d /src | |
parent | abc851a1de27e1dedab2b646a1568197b8189681 (diff) | |
download | scala-f309513c9f540e1e9eb5c072e66cb64333aa7bda.tar.gz scala-f309513c9f540e1e9eb5c072e66cb64333aa7bda.tar.bz2 scala-f309513c9f540e1e9eb5c072e66cb64333aa7bda.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.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/mutable/ArrayBuffer.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/ArrayOps.scala | 2 | ||||
-rw-r--r-- | 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 46499eb326..31a6f1f160 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) } |