Change BitVector class to be a zone object.

Change the BitVector utility class to allow allocation via 'new' in the
Zone.  Change the backing store to be always zone-allocated.

Review URL: http://codereview.chromium.org/730001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4071 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 60fa4084
...@@ -32,27 +32,31 @@ ...@@ -32,27 +32,31 @@
#include "ast.h" #include "ast.h"
#include "compiler.h" #include "compiler.h"
#include "zone-inl.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class BitVector BASE_EMBEDDED { class BitVector: public ZoneObject {
public: public:
explicit BitVector(int length) explicit BitVector(int length)
: length_(length), bits_(Vector<uint32_t>::New(1 + length / 32)) { : length_(length),
data_length_(SizeFor(length)),
data_(Zone::NewArray<uint32_t>(data_length_)) {
ASSERT(length > 0); ASSERT(length > 0);
for (int i = 0; i < bits_.length(); i++) { Clear();
bits_[i] = 0;
}
} }
BitVector(const BitVector& other) BitVector(const BitVector& other)
: length_(other.length()), : length_(other.length()),
bits_(Vector<uint32_t>::New(1 + other.length() / 32)) { data_length_(SizeFor(length_)),
data_(Zone::NewArray<uint32_t>(data_length_)) {
CopyFrom(other); CopyFrom(other);
} }
~BitVector() { bits_.Dispose(); } static int SizeFor(int length) {
return 1 + ((length - 1) / 32);
}
BitVector& operator=(const BitVector& rhs) { BitVector& operator=(const BitVector& rhs) {
if (this != &rhs) CopyFrom(rhs); if (this != &rhs) CopyFrom(rhs);
...@@ -61,50 +65,50 @@ class BitVector BASE_EMBEDDED { ...@@ -61,50 +65,50 @@ class BitVector BASE_EMBEDDED {
void CopyFrom(const BitVector& other) { void CopyFrom(const BitVector& other) {
ASSERT(other.length() == length()); ASSERT(other.length() == length());
for (int i = 0; i < bits_.length(); i++) { for (int i = 0; i < data_length_; i++) {
bits_[i] = other.bits_[i]; data_[i] = other.data_[i];
} }
} }
bool Contains(int i) { bool Contains(int i) {
ASSERT(i >= 0 && i < length()); ASSERT(i >= 0 && i < length());
uint32_t block = bits_[i / 32]; uint32_t block = data_[i / 32];
return (block & (1U << (i % 32))) != 0; return (block & (1U << (i % 32))) != 0;
} }
void Add(int i) { void Add(int i) {
ASSERT(i >= 0 && i < length()); ASSERT(i >= 0 && i < length());
bits_[i / 32] |= (1U << (i % 32)); data_[i / 32] |= (1U << (i % 32));
} }
void Remove(int i) { void Remove(int i) {
ASSERT(i >= 0 && i < length()); ASSERT(i >= 0 && i < length());
bits_[i / 32] &= ~(1U << (i % 32)); data_[i / 32] &= ~(1U << (i % 32));
} }
void Union(const BitVector& other) { void Union(const BitVector& other) {
ASSERT(other.length() == length()); ASSERT(other.length() == length());
for (int i = 0; i < bits_.length(); i++) { for (int i = 0; i < data_length_; i++) {
bits_[i] |= other.bits_[i]; data_[i] |= other.data_[i];
} }
} }
void Intersect(const BitVector& other) { void Intersect(const BitVector& other) {
ASSERT(other.length() == length()); ASSERT(other.length() == length());
for (int i = 0; i < bits_.length(); i++) { for (int i = 0; i < data_length_; i++) {
bits_[i] &= other.bits_[i]; data_[i] &= other.data_[i];
} }
} }
void Clear() { void Clear() {
for (int i = 0; i < bits_.length(); i++) { for (int i = 0; i < data_length_; i++) {
bits_[i] = 0; data_[i] = 0;
} }
} }
bool IsEmpty() { bool IsEmpty() const {
for (int i = 0; i < bits_.length(); i++) { for (int i = 0; i < data_length_; i++) {
if (bits_[i] != 0) return false; if (data_[i] != 0) return false;
} }
return true; return true;
} }
...@@ -113,7 +117,8 @@ class BitVector BASE_EMBEDDED { ...@@ -113,7 +117,8 @@ class BitVector BASE_EMBEDDED {
private: private:
int length_; int length_;
Vector<uint32_t> bits_; int data_length_;
uint32_t* data_;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment