Revision: 4071
Author: [email protected]
Date: Wed Mar 10 00:08:32 2010
Log: 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
http://code.google.com/p/v8/source/detail?r=4071

Modified:
 /branches/bleeding_edge/src/data-flow.h

=======================================
--- /branches/bleeding_edge/src/data-flow.h     Tue Mar  9 01:56:19 2010
+++ /branches/bleeding_edge/src/data-flow.h     Wed Mar 10 00:08:32 2010
@@ -32,27 +32,31 @@

 #include "ast.h"
 #include "compiler.h"
+#include "zone-inl.h"

 namespace v8 {
 namespace internal {

-class BitVector BASE_EMBEDDED {
+class BitVector: public ZoneObject {
  public:
   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);
-    for (int i = 0; i < bits_.length(); i++) {
-      bits_[i] = 0;
-    }
+    Clear();
   }

   BitVector(const BitVector& other)
       : 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);
   }

-  ~BitVector() { bits_.Dispose(); }
+  static int SizeFor(int length) {
+    return 1 + ((length - 1) / 32);
+  }

   BitVector& operator=(const BitVector& rhs) {
     if (this != &rhs) CopyFrom(rhs);
@@ -61,50 +65,50 @@

   void CopyFrom(const BitVector& other) {
     ASSERT(other.length() == length());
-    for (int i = 0; i < bits_.length(); i++) {
-      bits_[i] = other.bits_[i];
+    for (int i = 0; i < data_length_; i++) {
+      data_[i] = other.data_[i];
     }
   }

   bool Contains(int i) {
     ASSERT(i >= 0 && i < length());
-    uint32_t block = bits_[i / 32];
+    uint32_t block = data_[i / 32];
     return (block & (1U << (i % 32))) != 0;
   }

   void Add(int i) {
     ASSERT(i >= 0 && i < length());
-    bits_[i / 32] |= (1U << (i % 32));
+    data_[i / 32] |= (1U << (i % 32));
   }

   void Remove(int i) {
     ASSERT(i >= 0 && i < length());
-    bits_[i / 32] &= ~(1U << (i % 32));
+    data_[i / 32] &= ~(1U << (i % 32));
   }

   void Union(const BitVector& other) {
     ASSERT(other.length() == length());
-    for (int i = 0; i < bits_.length(); i++) {
-      bits_[i] |= other.bits_[i];
+    for (int i = 0; i < data_length_; i++) {
+      data_[i] |= other.data_[i];
     }
   }

   void Intersect(const BitVector& other) {
     ASSERT(other.length() == length());
-    for (int i = 0; i < bits_.length(); i++) {
-      bits_[i] &= other.bits_[i];
+    for (int i = 0; i < data_length_; i++) {
+      data_[i] &= other.data_[i];
     }
   }

   void Clear() {
-    for (int i = 0; i < bits_.length(); i++) {
-      bits_[i] = 0;
+    for (int i = 0; i < data_length_; i++) {
+      data_[i] = 0;
     }
   }

-  bool IsEmpty() {
-    for (int i = 0; i < bits_.length(); i++) {
-      if (bits_[i] != 0) return false;
+  bool IsEmpty() const {
+    for (int i = 0; i < data_length_; i++) {
+      if (data_[i] != 0) return false;
     }
     return true;
   }
@@ -113,7 +117,8 @@

  private:
   int length_;
-  Vector<uint32_t> bits_;
+  int data_length_;
+  uint32_t* data_;
 };


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to