Index: src/bit-vector.h |
diff --git a/src/data-flow.h b/src/bit-vector.h |
similarity index 79% |
rename from src/data-flow.h |
rename to src/bit-vector.h |
index bfd238d24ee326d52bdc902792f2d71a0ab8c59f..9fc747d06fae6ea0cf454a7d14047a595f832966 100644 |
--- a/src/data-flow.h |
+++ b/src/bit-vector.h |
@@ -15,7 +15,7 @@ |
namespace v8 { |
namespace internal { |
-class BitVector: public ZoneObject { |
+class BitVector : public ZoneObject { |
public: |
// Iterator for the elements of this BitVector. |
class Iterator BASE_EMBEDDED { |
@@ -28,7 +28,7 @@ class BitVector: public ZoneObject { |
DCHECK(target->data_length_ > 0); |
Advance(); |
} |
- ~Iterator() { } |
+ ~Iterator() {} |
bool Done() const { return current_index_ >= target_->data_length_; } |
void Advance(); |
@@ -39,14 +39,14 @@ class BitVector: public ZoneObject { |
} |
private: |
- uint32_t SkipZeroBytes(uint32_t val) { |
+ uintptr_t SkipZeroBytes(uintptr_t val) { |
while ((val & 0xFF) == 0) { |
val >>= 8; |
current_ += 8; |
} |
return val; |
} |
- uint32_t SkipZeroBits(uint32_t val) { |
+ uintptr_t SkipZeroBits(uintptr_t val) { |
while ((val & 0x1) == 0) { |
val >>= 1; |
current_++; |
@@ -56,16 +56,20 @@ class BitVector: public ZoneObject { |
BitVector* target_; |
int current_index_; |
- uint32_t current_value_; |
+ uintptr_t current_value_; |
int current_; |
friend class BitVector; |
}; |
+ static const int kDataBits = kPointerSize * 8; |
+ static const int kDataBitShift = kPointerSize == 8 ? 6 : 5; |
+ static const uintptr_t kOne = 1; // This saves some static_casts. |
+ |
BitVector(int length, Zone* zone) |
: length_(length), |
data_length_(SizeFor(length)), |
- data_(zone->NewArray<uint32_t>(data_length_)) { |
+ data_(zone->NewArray<uintptr_t>(data_length_)) { |
DCHECK(length > 0); |
Clear(); |
} |
@@ -73,18 +77,11 @@ class BitVector: public ZoneObject { |
BitVector(const BitVector& other, Zone* zone) |
: length_(other.length()), |
data_length_(SizeFor(length_)), |
- data_(zone->NewArray<uint32_t>(data_length_)) { |
+ data_(zone->NewArray<uintptr_t>(data_length_)) { |
CopyFrom(other); |
} |
- static int SizeFor(int length) { |
- return 1 + ((length - 1) / 32); |
- } |
- |
- BitVector& operator=(const BitVector& rhs) { |
- if (this != &rhs) CopyFrom(rhs); |
- return *this; |
- } |
+ static int SizeFor(int length) { return 1 + ((length - 1) / kDataBits); } |
void CopyFrom(const BitVector& other) { |
DCHECK(other.length() <= length()); |
@@ -98,18 +95,18 @@ class BitVector: public ZoneObject { |
bool Contains(int i) const { |
DCHECK(i >= 0 && i < length()); |
- uint32_t block = data_[i / 32]; |
- return (block & (1U << (i % 32))) != 0; |
+ uintptr_t block = data_[i / kDataBits]; |
+ return (block & (kOne << (i % kDataBits))) != 0; |
} |
void Add(int i) { |
DCHECK(i >= 0 && i < length()); |
- data_[i / 32] |= (1U << (i % 32)); |
+ data_[i / kDataBits] |= (kOne << (i % kDataBits)); |
} |
void Remove(int i) { |
DCHECK(i >= 0 && i < length()); |
- data_[i / 32] &= ~(1U << (i % 32)); |
+ data_[i / kDataBits] &= ~(kOne << (i % kDataBits)); |
} |
void Union(const BitVector& other) { |
@@ -123,7 +120,7 @@ class BitVector: public ZoneObject { |
DCHECK(other.length() == length()); |
bool changed = false; |
for (int i = 0; i < data_length_; i++) { |
- uint32_t old_data = data_[i]; |
+ uintptr_t old_data = data_[i]; |
data_[i] |= other.data_[i]; |
if (data_[i] != old_data) changed = true; |
} |
@@ -141,7 +138,7 @@ class BitVector: public ZoneObject { |
DCHECK(other.length() == length()); |
bool changed = false; |
for (int i = 0; i < data_length_; i++) { |
- uint32_t old_data = data_[i]; |
+ uintptr_t old_data = data_[i]; |
data_[i] &= other.data_[i]; |
if (data_[i] != old_data) changed = true; |
} |
@@ -184,9 +181,11 @@ class BitVector: public ZoneObject { |
#endif |
private: |
- int length_; |
- int data_length_; |
- uint32_t* data_; |
+ const int length_; |
+ const int data_length_; |
+ uintptr_t* const data_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BitVector); |
}; |
@@ -195,19 +194,19 @@ class GrowableBitVector BASE_EMBEDDED { |
class Iterator BASE_EMBEDDED { |
public: |
Iterator(const GrowableBitVector* target, Zone* zone) |
- : it_(target->bits_ == NULL |
- ? new(zone) BitVector(1, zone) |
- : target->bits_) { } |
+ : it_(target->bits_ == NULL ? new (zone) BitVector(1, zone) |
+ : target->bits_) {} |
bool Done() const { return it_.Done(); } |
void Advance() { it_.Advance(); } |
int Current() const { return it_.Current(); } |
+ |
private: |
BitVector::Iterator it_; |
}; |
- GrowableBitVector() : bits_(NULL) { } |
+ GrowableBitVector() : bits_(NULL) {} |
GrowableBitVector(int length, Zone* zone) |
- : bits_(new(zone) BitVector(length, zone)) { } |
+ : bits_(new (zone) BitVector(length, zone)) {} |
bool Contains(int value) const { |
if (!InBitsRange(value)) return false; |
@@ -225,7 +224,9 @@ class GrowableBitVector BASE_EMBEDDED { |
} |
} |
- void Clear() { if (bits_ != NULL) bits_->Clear(); } |
+ void Clear() { |
+ if (bits_ != NULL) bits_->Clear(); |
+ } |
private: |
static const int kInitialLength = 1024; |
@@ -238,7 +239,7 @@ class GrowableBitVector BASE_EMBEDDED { |
if (InBitsRange(value)) return; |
int new_length = bits_ == NULL ? kInitialLength : bits_->length(); |
while (new_length <= value) new_length *= 2; |
- BitVector* new_bits = new(zone) BitVector(new_length, zone); |
+ BitVector* new_bits = new (zone) BitVector(new_length, zone); |
if (bits_ != NULL) new_bits->CopyFrom(*bits_); |
bits_ = new_bits; |
} |