summaryrefslogtreecommitdiff
path: root/test/files/run/adding-growing-set.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-04-23 21:20:14 +0000
committerPaul Phillips <paulp@improving.org>2010-04-23 21:20:14 +0000
commiteb1ee924dd922db2e967c8a38ec13410eeb7110f (patch)
treec47f0b34931797ebf271d41b0e13ec9d42e6032c /test/files/run/adding-growing-set.scala
parentdb8bd90da4c78e543bad65dea5600febc6fbbd20 (diff)
downloadscala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.tar.gz
scala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.tar.bz2
scala-eb1ee924dd922db2e967c8a38ec13410eeb7110f.zip
Created Mutable and Immutable SetFactories to d...
Created Mutable and Immutable SetFactories to deal with the spectacular performance regression which accompanies the use of AddingBuilder on mutable Sets. Because '+' now creates a new collection even on mutable sets, AddingBuilder on a 100K element collection will create garbage sets of size 1,2,3...,99,999 before finishing. Thankfully there is already GrowingBuilder. See test/files/run/adding-growing-set.scala for a demonstration. This patch is not complete: in particular, SortedSet and SetBuilder need attention. Unfortunately there is a combinatorial jump in the number of Addable/Growable divisions which arises once one tries to accomodate both Sorted signatures (taking an Ordering) and unsorted signatures, so will come back to it after receiving counsel. Review by odersky.
Diffstat (limited to 'test/files/run/adding-growing-set.scala')
-rw-r--r--test/files/run/adding-growing-set.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/files/run/adding-growing-set.scala b/test/files/run/adding-growing-set.scala
new file mode 100644
index 0000000000..5903813ed1
--- /dev/null
+++ b/test/files/run/adding-growing-set.scala
@@ -0,0 +1,11 @@
+/** This will run a a loooong time if Set's builder copies a
+ * complete new Set for every element.
+ */
+object Test {
+ def main(args: Array[String]): Unit = {
+ val a = new Array[Long](1000000)
+ (1 to 10000) foreach (i => a(i) = i)
+ val s = collection.mutable.Set(a: _*)
+ assert(s.sum > 0)
+ }
+}