Index: runtime/vm/bit_set.h |
=================================================================== |
--- runtime/vm/bit_set.h (revision 39806) |
+++ runtime/vm/bit_set.h (working copy) |
@@ -22,38 +22,49 @@ |
void Set(intptr_t i, bool value) { |
ASSERT(i >= 0); |
ASSERT(i < N); |
- uword mask = (static_cast<uword>(1) << (i % kBitsPerWord)); |
+ uword mask = (static_cast<uword>(1) << (i & (kBitsPerWord - 1))); |
if (value) { |
- data_[i / kBitsPerWord] |= mask; |
+ data_[i >> kBitsPerWordLog2] |= mask; |
} else { |
- data_[i / kBitsPerWord] &= ~mask; |
+ data_[i >> kBitsPerWordLog2] &= ~mask; |
} |
} |
- bool Test(intptr_t i) { |
+ bool Test(intptr_t i) const { |
ASSERT(i >= 0); |
ASSERT(i < N); |
- uword mask = (static_cast<uword>(1) << (i % kBitsPerWord)); |
- return (data_[i / kBitsPerWord] & mask) != 0; |
+ uword mask = (static_cast<uword>(1) << (i & (kBitsPerWord - 1))); |
+ return (data_[i >> kBitsPerWordLog2] & mask) != 0; |
} |
- intptr_t Next(intptr_t i) { |
+ intptr_t Next(intptr_t i) const { |
ASSERT(i >= 0); |
ASSERT(i < N); |
- intptr_t w = i / kBitsPerWord; |
+ intptr_t w = i >> kBitsPerWordLog2; |
uword mask = ~static_cast<uword>(0) << i; |
if ((data_[w] & mask) != 0) { |
uword tz = Utils::CountTrailingZeros(data_[w] & mask); |
- return kBitsPerWord*w + tz; |
+ return (w << kBitsPerWordLog2) + tz; |
} |
- while (++w < (1 + ((N - 1) / kBitsPerWord))) { |
+ while (++w < kLengthInWords) { |
if (data_[w] != 0) { |
- return kBitsPerWord*w + Utils::CountTrailingZeros(data_[w]); |
+ return (w << kBitsPerWordLog2) + Utils::CountTrailingZeros(data_[w]); |
} |
} |
return -1; |
} |
+ intptr_t Last() const { |
+ for (int w = kLengthInWords - 1; w >= 0; --w) { |
+ uword d = data_[w]; |
+ if (d != 0) { |
+ // TODO(koda): Define HighestBit(uword) or use uint64_t[] for data_. |
+ return (w << kBitsPerWordLog2) + Utils::HighestBit(d); |
+ } |
+ } |
+ return -1; |
+ } |
+ |
void Reset() { |
memset(data_, 0, sizeof(data_)); |
} |
@@ -63,7 +74,8 @@ |
} |
private: |
- uword data_[1 + ((N - 1) / kBitsPerWord)]; |
+ static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); |
+ uword data_[kLengthInWords]; |
}; |
} // namespace dart |