diff options
author | Chris Lattner <sabre@nondot.org> | 2007-10-12 03:48:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-10-12 03:48:59 +0000 |
commit | 886636445deeeb9283d262411a6fbe83b65056ab (patch) | |
tree | 1ef2352eb9c24fb0df147281154f1b4a08ae1a7b /include/llvm/ADT/BitVector.h | |
parent | ca68aaa0e50c4037c0faa9bfbe7e091087837259 (diff) |
make operator== work with non-equal sized bitvectors, as long as
the extra bits are all zeros. This allows "010" and "010000" to be
treated as equal.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42889 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/BitVector.h')
-rw-r--r-- | include/llvm/ADT/BitVector.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h index dc408af4ae..000cdd3d67 100644 --- a/include/llvm/ADT/BitVector.h +++ b/include/llvm/ADT/BitVector.h @@ -259,12 +259,23 @@ public: // Comparison operators. bool operator==(const BitVector &RHS) const { - if (Size != RHS.Size) - return false; - - for (unsigned i = 0; i < NumBitWords(size()); ++i) + unsigned ThisWords = NumBitWords(size()); + unsigned RHSWords = NumBitWords(RHS.size()); + unsigned i; + for (i = 0; i != std::min(ThisWords, RHSWords); ++i) if (Bits[i] != RHS.Bits[i]) return false; + + // Verify that any extra words are all zeros. + if (i != ThisWords) { + for (; i != ThisWords; ++i) + if (Bits[i]) + return false; + } else if (i != RHSWords) { + for (; i != RHSWords; ++i) + if (RHS.Bits[i]) + return false; + } return true; } |