forked from OSchip/llvm-project
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:
parent
05ff9e8cda
commit
7119397fa1
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue