[llvm-commits] [llvm] r42889 - /llvm/trunk/include/llvm/ADT/BitVector.h

Chris Lattner sabre at nondot.org
Thu Oct 11 20:49:00 PDT 2007


Author: lattner
Date: Thu Oct 11 22:48:59 2007
New Revision: 42889

URL: http://llvm.org/viewvc/llvm-project?rev=42889&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/ADT/BitVector.h

Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=42889&r1=42888&r2=42889&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Thu Oct 11 22:48:59 2007
@@ -259,12 +259,23 @@
 
   // 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;
   }
 





More information about the llvm-commits mailing list