diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-06-07 15:14:31 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-06-07 15:14:31 +0000 |
commit | a77376dae1e26572f94aa52b63f89749b785bc33 (patch) | |
tree | b5b1d8ae91015bdb2895b4ee3c9f5def314660a4 /include | |
parent | 597253da97ec4fa5fa4a03c2230ed026b1b6aad6 (diff) | |
download | external_llvm-a77376dae1e26572f94aa52b63f89749b785bc33.zip external_llvm-a77376dae1e26572f94aa52b63f89749b785bc33.tar.gz external_llvm-a77376dae1e26572f94aa52b63f89749b785bc33.tar.bz2 |
BitVector: Do the right thing in all() when Size is a multiple of BITWORD_SIZE.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183525 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/BitVector.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h index 8f512f5..8fb538f 100644 --- a/include/llvm/ADT/BitVector.h +++ b/include/llvm/ADT/BitVector.h @@ -138,16 +138,15 @@ public: /// all - Returns true if all bits are set. bool all() const { - if (empty()) - return true; - - for (unsigned i = 0; i < NumBitWords(size()) - 1; ++i) + for (unsigned i = 0; i < Size / BITWORD_SIZE; ++i) if (Bits[i] != ~0UL) return false; - // For the last word check that the lower bits are ones. The unused bits are - // always zero. - return Bits[NumBitWords(size()) - 1] == ~(~0UL << (Size % BITWORD_SIZE)); + // If bits remain check that they are ones. The unused bits are always zero. + if (unsigned Remainder = Size % BITWORD_SIZE) + return Bits[Size / BITWORD_SIZE] == (1UL << Remainder) - 1; + + return true; } /// none - Returns true if none of the bits are set. |