summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/BitVector.h
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-02-15 18:59:15 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-02-15 18:59:15 +0000
commit5f92ce4696eaeca9d8b99b1a1fa784e78479d516 (patch)
tree33444fb66817ddcdaad080af9f31d0b8f01d0e91 /include/llvm/ADT/BitVector.h
parent924b1ca9ee02b648149d76b62e30f5d9c0ebbf27 (diff)
downloadllvm-5f92ce4696eaeca9d8b99b1a1fa784e78479d516.tar.gz
llvm-5f92ce4696eaeca9d8b99b1a1fa784e78479d516.tar.bz2
llvm-5f92ce4696eaeca9d8b99b1a1fa784e78479d516.tar.xz
Eliminate new[0], just set Bits to NULL.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34311 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/BitVector.h')
-rw-r--r--include/llvm/ADT/BitVector.h31
1 files changed, 20 insertions, 11 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index 8653545134..0315172ebd 100644
--- a/include/llvm/ADT/BitVector.h
+++ b/include/llvm/ADT/BitVector.h
@@ -69,7 +69,7 @@ public:
/// BitVector default ctor - Creates an empty bitvector.
BitVector() : Size(0), Capacity(0) {
- Bits = new BitWord[0];
+ Bits = NULL;
}
/// BitVector ctor - Creates a bitvector of specified number of bits. All
@@ -154,9 +154,11 @@ public:
/// clear - Clear all bits.
void clear() {
- delete[] Bits;
- Bits = new BitWord[0];
- Size = Capacity = 0;
+ if (Capacity > 0) {
+ delete[] Bits;
+ Bits = NULL;
+ Size = Capacity = 0;
+ }
}
/// resize - Grow or shrink the bitvector.
@@ -186,8 +188,10 @@ public:
// Set, reset, flip
BitVector &set() {
- init_words(Bits, Capacity, true);
- clear_unused_bits();
+ if (Bits) {
+ init_words(Bits, Capacity, true);
+ clear_unused_bits();
+ }
return *this;
}
@@ -197,7 +201,8 @@ public:
}
BitVector &reset() {
- init_words(Bits, Capacity, false);
+ if (Bits)
+ init_words(Bits, Capacity, false);
return *this;
}
@@ -303,8 +308,10 @@ private:
// Clear the unused top bits in the high word.
void clear_unused_bits() {
- unsigned ExtraBits = Size % BITS_PER_WORD;
- Bits[Size / BITS_PER_WORD] &= ~(~0 << ExtraBits);
+ if (Size) {
+ unsigned ExtraBits = Size % BITS_PER_WORD;
+ Bits[Size / BITS_PER_WORD] &= ~(~0 << ExtraBits);
+ }
}
void grow(unsigned NewSize) {
@@ -317,12 +324,14 @@ private:
std::copy(Bits, &Bits[OldCapacity], NewBits);
// Destroy the old bits.
- delete[] Bits;
+ if (Bits)
+ delete[] Bits;
Bits = NewBits;
}
void init_words(BitWord *B, unsigned NumWords, bool t) {
- memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
+ if (B)
+ memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
}
};