From d33ba3bb9c5f09374dd585cc6f0ff6294b98fc6a Mon Sep 17 00:00:00 2001 From: Alissa Rao Date: Tue, 14 Oct 2014 18:06:53 -0500 Subject: 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. --- .../scala/collection/mutable/BitSetTest.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/junit/scala/collection/mutable/BitSetTest.scala (limited to 'test') 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 &~=") + } +} -- cgit v1.2.3