[llvm-commits] CVS: llvm/include/llvm/ADT/BitVector.h

Evan Cheng evan.cheng at apple.com
Thu Feb 15 00:16:17 PST 2007



Changes in directory llvm/include/llvm/ADT:

BitVector.h updated: 1.1 -> 1.2
---
Log message:

Bug fixes: assignment operator forgot to copy over size; copy ctor forgot to clear unused top bits.

---
Diffs of the changes:  (+6 -5)

 BitVector.h |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)


Index: llvm/include/llvm/ADT/BitVector.h
diff -u llvm/include/llvm/ADT/BitVector.h:1.1 llvm/include/llvm/ADT/BitVector.h:1.2
--- llvm/include/llvm/ADT/BitVector.h:1.1	Wed Feb 14 23:56:11 2007
+++ llvm/include/llvm/ADT/BitVector.h	Thu Feb 15 02:15:58 2007
@@ -86,6 +86,7 @@
     Capacity = NumBitWords(s);
     Bits = new BitWord[Capacity];
     init_words(Bits, Capacity, t);
+    clear_unused_bits();
   }
 
   /// BitVector copy ctor.
@@ -175,6 +176,7 @@
       init_words(&Bits[OldCapacity], (Capacity-OldCapacity), t);
     }
     Size = N;
+    clear_unused_bits();
   }
 
   void reserve(unsigned N) {
@@ -274,17 +276,16 @@
   const BitVector &operator=(const BitVector &RHS) {
     if (this == &RHS) return *this;
 
-    unsigned RHSWords = NumBitWords(RHS.size());
-    unsigned NewSize = RHS.size();
-    if (NewSize <= Capacity * BITS_PER_WORD) {
+    Size = RHS.size();
+    unsigned RHSWords = NumBitWords(Size);
+    if (Size > Capacity * BITS_PER_WORD) {
       std::copy(RHS.Bits, &RHS.Bits[RHSWords], Bits);
-      Size = NewSize;
       clear_unused_bits();
       return *this;
     }
   
     // Grow the bitvector to have enough elements.
-    Capacity = NumBitWords(NewSize);
+    Capacity = NumBitWords(Size);
     BitWord *NewBits = new BitWord[Capacity];
     std::copy(RHS.Bits, &RHS.Bits[RHSWords], NewBits);
 






More information about the llvm-commits mailing list