summaryrefslogtreecommitdiff
path: root/src/library
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 /src/library
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 'src/library')
-rw-r--r--src/library/scala/collection/mutable/BitSet.scala8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala
index 43d23acc1a..faa4155317 100644
--- a/src/library/scala/collection/mutable/BitSet.scala
+++ b/src/library/scala/collection/mutable/BitSet.scala
@@ -110,7 +110,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int]
* @return the bitset itself.
*/
def |= (other: BitSet): this.type = {
- ensureCapacity(other.nwords)
+ ensureCapacity(other.nwords - 1)
for (i <- 0 until other.nwords)
elems(i) = elems(i) | other.word(i)
this
@@ -121,7 +121,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int]
* @return the bitset itself.
*/
def &= (other: BitSet): this.type = {
- ensureCapacity(other.nwords)
+ ensureCapacity(other.nwords - 1)
for (i <- 0 until other.nwords)
elems(i) = elems(i) & other.word(i)
this
@@ -132,7 +132,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int]
* @return the bitset itself.
*/
def ^= (other: BitSet): this.type = {
- ensureCapacity(other.nwords)
+ ensureCapacity(other.nwords - 1)
for (i <- 0 until other.nwords)
elems(i) = elems(i) ^ other.word(i)
this
@@ -143,7 +143,7 @@ class BitSet(protected final var elems: Array[Long]) extends AbstractSet[Int]
* @return the bitset itself.
*/
def &~= (other: BitSet): this.type = {
- ensureCapacity(other.nwords)
+ ensureCapacity(other.nwords - 1)
for (i <- 0 until other.nwords)
elems(i) = elems(i) & ~other.word(i)
this