| Index: src/unique.h
|
| diff --git a/src/unique.h b/src/unique.h
|
| index 82ed652391355785b9fba49826b353c3211f2b9b..8ed26829012c3980139d1a5d71c6d053e70eebe4 100644
|
| --- a/src/unique.h
|
| +++ b/src/unique.h
|
| @@ -134,6 +134,19 @@ class UniqueSet V8_FINAL : public ZoneObject {
|
| // Constructor. A new set will be empty.
|
| UniqueSet() : size_(0), capacity_(0), array_(NULL) { }
|
|
|
| + // Capacity constructor. A new set will be empty.
|
| + UniqueSet(int capacity, Zone* zone)
|
| + : size_(0), capacity_(capacity),
|
| + array_(zone->NewArray<Unique<T> >(capacity)) {
|
| + ASSERT(capacity <= kMaxCapacity);
|
| + }
|
| +
|
| + // Singleton constructor.
|
| + UniqueSet(Unique<T> uniq, Zone* zone)
|
| + : size_(1), capacity_(1), array_(zone->NewArray<Unique<T> >(1)) {
|
| + array_[0] = uniq;
|
| + }
|
| +
|
| // Add a new element to this unique set. Mutates this set. O(|this|).
|
| void Add(Unique<T> uniq, Zone* zone) {
|
| ASSERT(uniq.IsInitialized());
|
| @@ -178,8 +191,11 @@ class UniqueSet V8_FINAL : public ZoneObject {
|
| // TODO(titzer): use binary search for large sets to make this O(log|this|)
|
| template <typename U>
|
| bool Contains(const Unique<U> elem) const {
|
| - for (int i = 0; i < size_; i++) {
|
| - if (this->array_[i] == elem) return true;
|
| + for (int i = 0; i < this->size_; ++i) {
|
| + Unique<T> cand = this->array_[i];
|
| + if (cand.raw_address_ >= elem.raw_address_) {
|
| + return cand.raw_address_ == elem.raw_address_;
|
| + }
|
| }
|
| return false;
|
| }
|
| @@ -201,11 +217,11 @@ class UniqueSet V8_FINAL : public ZoneObject {
|
|
|
| // Returns a new set representing the intersection of this set and the other.
|
| // O(|this| + |that|).
|
| - UniqueSet<T>* Intersect(UniqueSet<T>* that, Zone* zone) const {
|
| + UniqueSet<T>* Intersect(const UniqueSet<T>* that, Zone* zone) const {
|
| if (that->size_ == 0 || this->size_ == 0) return new(zone) UniqueSet<T>();
|
|
|
| - UniqueSet<T>* out = new(zone) UniqueSet<T>();
|
| - out->Grow(Min(this->size_, that->size_), zone);
|
| + UniqueSet<T>* out = new(zone) UniqueSet<T>(
|
| + Min(this->size_, that->size_), zone);
|
|
|
| int i = 0, j = 0, k = 0;
|
| while (i < this->size_ && j < that->size_) {
|
| @@ -228,12 +244,12 @@ class UniqueSet V8_FINAL : public ZoneObject {
|
|
|
| // Returns a new set representing the union of this set and the other.
|
| // O(|this| + |that|).
|
| - UniqueSet<T>* Union(UniqueSet<T>* that, Zone* zone) const {
|
| + UniqueSet<T>* Union(const UniqueSet<T>* that, Zone* zone) const {
|
| if (that->size_ == 0) return this->Copy(zone);
|
| if (this->size_ == 0) return that->Copy(zone);
|
|
|
| - UniqueSet<T>* out = new(zone) UniqueSet<T>();
|
| - out->Grow(this->size_ + that->size_, zone);
|
| + UniqueSet<T>* out = new(zone) UniqueSet<T>(
|
| + this->size_ + that->size_, zone);
|
|
|
| int i = 0, j = 0, k = 0;
|
| while (i < this->size_ && j < that->size_) {
|
| @@ -261,10 +277,8 @@ class UniqueSet V8_FINAL : public ZoneObject {
|
|
|
| // Makes an exact copy of this set. O(|this|).
|
| UniqueSet<T>* Copy(Zone* zone) const {
|
| - UniqueSet<T>* copy = new(zone) UniqueSet<T>();
|
| + UniqueSet<T>* copy = new(zone) UniqueSet<T>(this->size_, zone);
|
| copy->size_ = this->size_;
|
| - copy->capacity_ = this->size_;
|
| - copy->array_ = zone->NewArray<Unique<T> >(this->size_);
|
| memcpy(copy->array_, this->array_, this->size_ * sizeof(Unique<T>));
|
| return copy;
|
| }
|
|
|