Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: src/data-flow.h

Issue 683243005: convert BitVector to use pointer size blocks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/data-flow.cc » ('j') | src/data-flow.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/data-flow.h
diff --git a/src/data-flow.h b/src/data-flow.h
index bfd238d24ee326d52bdc902792f2d71a0ab8c59f..ac8220d22680037107626d3afe4f03bbe6d8c67b 100644
--- a/src/data-flow.h
+++ b/src/data-flow.h
@@ -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);
};
« no previous file with comments | « no previous file | src/data-flow.cc » ('j') | src/data-flow.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698