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.

llvm-svn: 42889
This commit is contained in:
Chris Lattner 2007-10-12 03:48:59 +00:00
parent 05ff9e8cda
commit 7119397fa1
1 changed files with 15 additions and 4 deletions

View File

@ -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;
}