From eb1ee924dd922db2e967c8a38ec13410eeb7110f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 23 Apr 2010 21:20:14 +0000 Subject: 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. --- test/files/run/adding-growing-set.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/files/run/adding-growing-set.scala (limited to 'test/files') 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) + } +} -- cgit v1.2.3