diff options
author | Vladimir Marko <vmarko@google.com> | 2014-03-11 12:42:25 +0000 |
---|---|---|
committer | Vladimir Marko <vmarko@google.com> | 2014-03-11 12:43:22 +0000 |
commit | 4812d436ebf538043a7827253b2e940a52a43fcb (patch) | |
tree | 18667db8756044a2625385b9ac3eab2a94451678 /runtime/base | |
parent | b28bdd624b63a52e4a69b93fa9abee6fbd393610 (diff) | |
download | art-4812d436ebf538043a7827253b2e940a52a43fcb.zip art-4812d436ebf538043a7827253b2e940a52a43fcb.tar.gz art-4812d436ebf538043a7827253b2e940a52a43fcb.tar.bz2 |
Fix BitVector::SetInitialBits().
Change-Id: Iad3699d76ad69536aa4810329f5863bc995f6551
Diffstat (limited to 'runtime/base')
-rw-r--r-- | runtime/base/bit_vector.cc | 1 | ||||
-rw-r--r-- | runtime/base/bit_vector_test.cc | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/runtime/base/bit_vector.cc b/runtime/base/bit_vector.cc index 3db8e12..590835e 100644 --- a/runtime/base/bit_vector.cc +++ b/runtime/base/bit_vector.cc @@ -265,6 +265,7 @@ void BitVector::SetInitialBits(uint32_t num_bits) { uint32_t rem_num_bits = num_bits & 0x1f; if (rem_num_bits != 0) { storage_[idx] = (1 << rem_num_bits) - 1; + ++idx; } // Now set the upper ones to 0. diff --git a/runtime/base/bit_vector_test.cc b/runtime/base/bit_vector_test.cc index 3fc9b86..a67fb33 100644 --- a/runtime/base/bit_vector_test.cc +++ b/runtime/base/bit_vector_test.cc @@ -119,4 +119,23 @@ TEST(BitVector, NoopAllocator) { EXPECT_EQ(4U, bv.NumSetBits(63)); } +TEST(BitVector, SetInitialBits) { + const uint32_t kWords = 2; + + uint32_t bits[kWords]; + memset(bits, 0, sizeof(bits)); + + BitVector bv(0U, false, Allocator::GetNoopAllocator(), kWords, bits); + bv.SetInitialBits(0u); + EXPECT_EQ(0u, bv.NumSetBits()); + bv.SetInitialBits(1u); + EXPECT_EQ(1u, bv.NumSetBits()); + bv.SetInitialBits(32u); + EXPECT_EQ(32u, bv.NumSetBits()); + bv.SetInitialBits(63u); + EXPECT_EQ(63u, bv.NumSetBits()); + bv.SetInitialBits(64u); + EXPECT_EQ(64u, bv.NumSetBits()); +} + } // namespace art |