diff options
author | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-21 12:14:52 +0400 |
---|---|---|
committer | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-03-21 21:32:54 +0400 |
commit | 1b3a379e7b0518279ceae3a47135df35b4fe3439 (patch) | |
tree | ccaf2095c04a70056316745e92615b8697267733 /src | |
parent | 7adab908d661f1b238a96972e96ed11ea497bcdc (diff) | |
download | scala-1b3a379e7b0518279ceae3a47135df35b4fe3439.tar.gz scala-1b3a379e7b0518279ceae3a47135df35b4fe3439.tar.bz2 scala-1b3a379e7b0518279ceae3a47135df35b4fe3439.zip |
SI-7102 Specialize isEmpty for bitsets
Currently bitsets use default isEmpty implementation inherited from
Set, which tests for "size == 0".
Calculating the size of a word in a bitmap requires summing through
all bits set, whereas testing for emptyness needs only one comparison
with zero.
This commit overrides the default implementation with the specialized
one looking for a non-zero word in this bitmap.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/BitSetLike.scala | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/library/scala/collection/BitSetLike.scala b/src/library/scala/collection/BitSetLike.scala index 72a6713ffd..034ed2b24a 100644 --- a/src/library/scala/collection/BitSetLike.scala +++ b/src/library/scala/collection/BitSetLike.scala @@ -69,6 +69,8 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe s } + override def isEmpty: Boolean = 0 until nwords forall (i => word(i) == 0) + implicit def ordering: Ordering[Int] = Ordering.Int def rangeImpl(from: Option[Int], until: Option[Int]): This = { |