Revision: 4063
Author: [email protected]
Date: Tue Mar 9 01:51:37 2010
Log: Add copy constructor and assignment operator to the BitVector class.
Review URL: http://codereview.chromium.org/668259
http://code.google.com/p/v8/source/detail?r=4063
Modified:
/branches/bleeding_edge/src/data-flow.h
/branches/bleeding_edge/test/cctest/test-dataflow.cc
=======================================
--- /branches/bleeding_edge/src/data-flow.h Mon Mar 8 04:53:11 2010
+++ /branches/bleeding_edge/src/data-flow.h Tue Mar 9 01:51:37 2010
@@ -36,17 +36,28 @@
namespace v8 {
namespace internal {
-class BitVector {
+class BitVector BASE_EMBEDDED {
public:
- explicit BitVector(int length) : length_(length) {
+ explicit BitVector(int length)
+ : length_(length), bits_(Vector<uint32_t>::New(1 + length / 32)) {
ASSERT(length > 0);
- bits_ = Vector<uint32_t>::New(1 + length / 32);
for (int i = 0; i < bits_.length(); i++) {
bits_[i] = 0;
}
}
+
+ BitVector(const BitVector& other)
+ : length_(other.length()),
+ bits_(Vector<uint32_t>::New(1 + other.length() / 32)) {
+ CopyFrom(other);
+ }
~BitVector() { bits_.Dispose(); }
+
+ BitVector& operator=(const BitVector& rhs) {
+ if (this != &rhs) CopyFrom(rhs);
+ return *this;
+ }
void CopyFrom(const BitVector& other) {
ASSERT(other.length() == length());
@@ -84,14 +95,25 @@
bits_[i] &= other.bits_[i];
}
}
+
+ void Clear() {
+ for (int i = 0; i < bits_.length(); i++) {
+ bits_[i] = 0;
+ }
+ }
+
+ bool IsEmpty() {
+ for (int i = 0; i < bits_.length(); i++) {
+ if (bits_[i] != 0) return false;
+ }
+ return true;
+ }
int length() const { return length_; }
private:
int length_;
Vector<uint32_t> bits_;
-
- DISALLOW_COPY_AND_ASSIGN(BitVector);
};
=======================================
--- /branches/bleeding_edge/test/cctest/test-dataflow.cc Tue Mar 2
02:43:46 2010
+++ /branches/bleeding_edge/test/cctest/test-dataflow.cc Tue Mar 9
01:51:37 2010
@@ -59,6 +59,21 @@
CHECK(v.Contains(0));
CHECK(v.Contains(1));
}
+
+ {
+ BitVector v(15);
+ v.Add(0);
+ BitVector w(15);
+ w = v;
+ CHECK(w.Contains(0));
+ w.Add(1);
+ BitVector u(w);
+ CHECK(u.Contains(0));
+ CHECK(u.Contains(1));
+ v.Union(w);
+ CHECK(v.Contains(0));
+ CHECK(v.Contains(1));
+ }
{
BitVector v(35);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev