aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-10-12 03:48:59 +0000
committerChris Lattner <sabre@nondot.org>2007-10-12 03:48:59 +0000
commitc8c31f71c422d6e73c75f7af050bb0fb782dd41b (patch)
tree1ef2352eb9c24fb0df147281154f1b4a08ae1a7b /include
parent4c14d512ea8e8fd8ec625604cf82275e319303d9 (diff)
downloadexternal_llvm-c8c31f71c422d6e73c75f7af050bb0fb782dd41b.zip
external_llvm-c8c31f71c422d6e73c75f7af050bb0fb782dd41b.tar.gz
external_llvm-c8c31f71c422d6e73c75f7af050bb0fb782dd41b.tar.bz2
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')
-rw-r--r--include/llvm/ADT/BitVector.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index dc408af..000cdd3 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;
}