summaryrefslogtreecommitdiff
path: root/test/junit/scala/collection/mutable/BitSetTest.scala
diff options
context:
space:
mode:
authorAlissa Rao <lymia@lymiahugs.com>2014-10-14 18:06:53 -0500
committerAlissa Rao <lymia@lymiahugs.com>2014-10-15 17:59:53 -0500
commitd33ba3bb9c5f09374dd585cc6f0ff6294b98fc6a (patch)
treebc3e1763d20226a5a2afbea1036ff0b485f6047d /test/junit/scala/collection/mutable/BitSetTest.scala
parent2b5df373638d08204b71258928289f6b39e25d5f (diff)
downloadscala-d33ba3bb9c5f09374dd585cc6f0ff6294b98fc6a.tar.gz
scala-d33ba3bb9c5f09374dd585cc6f0ff6294b98fc6a.tar.bz2
scala-d33ba3bb9c5f09374dd585cc6f0ff6294b98fc6a.zip
SI-8910 BitSet sometimes uses exponential memory.
Because of an off-by-one error in scala.collection.mutable.BitSet, where a function (ensureCapacity) is passed a list length instead of an index, when ^=, &=, |=, or &~= are passed BitSets with the same internal capacity as the set the method is being invoked on, the size of the first BitSet is needlessly doubled. This patch simply changes the ensureCapacity calls to pass the last index of the list, instead of the raw length. In addition, add documentation to ensureCapacity to try and stop something similar from happening in the future.
Diffstat (limited to 'test/junit/scala/collection/mutable/BitSetTest.scala')
-rw-r--r--test/junit/scala/collection/mutable/BitSetTest.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/junit/scala/collection/mutable/BitSetTest.scala b/test/junit/scala/collection/mutable/BitSetTest.scala
new file mode 100644
index 0000000000..8d164b50d4
--- /dev/null
+++ b/test/junit/scala/collection/mutable/BitSetTest.scala
@@ -0,0 +1,22 @@
+package scala.collection.mutable
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.{Test, Ignore}
+
+@RunWith(classOf[JUnit4])
+class BitSetTest {
+ // Test for SI-8910
+ @Test def capacityExpansionTest() {
+ val bitSet = BitSet.empty
+ val size = bitSet.toBitMask.length
+ bitSet ^= bitSet
+ assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after ^=")
+ bitSet |= bitSet
+ assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after |=")
+ bitSet &= bitSet
+ assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &=")
+ bitSet &~= bitSet
+ assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &~=")
+ }
+}