| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 inline bool IsKnownGlobal(void* global) const { | 114 inline bool IsKnownGlobal(void* global) const { |
| 115 ASSERT(IsInitialized()); | 115 ASSERT(IsInitialized()); |
| 116 return raw_address_ == reinterpret_cast<Address>(global); | 116 return raw_address_ == reinterpret_cast<Address>(global); |
| 117 } | 117 } |
| 118 | 118 |
| 119 inline Handle<T> handle() const { | 119 inline Handle<T> handle() const { |
| 120 return handle_; | 120 return handle_; |
| 121 } | 121 } |
| 122 | 122 |
| 123 template <class S> static Unique<T> cast(Unique<S> that) { |
| 124 return Unique<T>(that.raw_address_, Handle<T>::cast(that.handle_)); |
| 125 } |
| 126 |
| 123 inline bool IsInitialized() const { | 127 inline bool IsInitialized() const { |
| 124 return raw_address_ != NULL || handle_.is_null(); | 128 return raw_address_ != NULL || handle_.is_null(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally. | 131 // TODO(titzer): this is a hack to migrate to Unique<T> incrementally. |
| 128 static Unique<T> CreateUninitialized(Handle<T> handle) { | 132 static Unique<T> CreateUninitialized(Handle<T> handle) { |
| 129 return Unique<T>(reinterpret_cast<Address>(NULL), handle); | 133 return Unique<T>(reinterpret_cast<Address>(NULL), handle); |
| 130 } | 134 } |
| 131 | 135 |
| 132 static Unique<T> CreateImmovable(Handle<T> handle) { | 136 static Unique<T> CreateImmovable(Handle<T> handle) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 162 array_[i] = uniq; | 166 array_[i] = uniq; |
| 163 size_++; | 167 size_++; |
| 164 return; | 168 return; |
| 165 } | 169 } |
| 166 } | 170 } |
| 167 // Append the element to the the end. | 171 // Append the element to the the end. |
| 168 Grow(size_ + 1, zone); | 172 Grow(size_ + 1, zone); |
| 169 array_[size_++] = uniq; | 173 array_[size_++] = uniq; |
| 170 } | 174 } |
| 171 | 175 |
| 176 // Remove an element from this set. Mutates this set. O(|this|) |
| 177 void Remove(Unique<T> uniq) { |
| 178 for (int i = 0; i < size_; i++) { |
| 179 if (array_[i] == uniq) { |
| 180 while (++i < size_) array_[i - 1] = array_[i]; |
| 181 size_--; |
| 182 return; |
| 183 } |
| 184 } |
| 185 } |
| 186 |
| 172 // Compare this set against another set. O(|this|). | 187 // Compare this set against another set. O(|this|). |
| 173 bool Equals(UniqueSet<T>* that) const { | 188 bool Equals(UniqueSet<T>* that) const { |
| 174 if (that->size_ != this->size_) return false; | 189 if (that->size_ != this->size_) return false; |
| 175 for (int i = 0; i < this->size_; i++) { | 190 for (int i = 0; i < this->size_; i++) { |
| 176 if (this->array_[i] != that->array_[i]) return false; | 191 if (this->array_[i] != that->array_[i]) return false; |
| 177 } | 192 } |
| 178 return true; | 193 return true; |
| 179 } | 194 } |
| 180 | 195 |
| 181 // Check whether this set contains the given element. O(|this|) | 196 // Check whether this set contains the given element. O(|this|) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Makes an exact copy of this set. O(|this| + |that|). | 281 // Makes an exact copy of this set. O(|this| + |that|). |
| 267 UniqueSet<T>* Copy(Zone* zone) const { | 282 UniqueSet<T>* Copy(Zone* zone) const { |
| 268 UniqueSet<T>* copy = new(zone) UniqueSet<T>(); | 283 UniqueSet<T>* copy = new(zone) UniqueSet<T>(); |
| 269 copy->size_ = this->size_; | 284 copy->size_ = this->size_; |
| 270 copy->capacity_ = this->size_; | 285 copy->capacity_ = this->size_; |
| 271 copy->array_ = zone->NewArray<Unique<T> >(this->size_); | 286 copy->array_ = zone->NewArray<Unique<T> >(this->size_); |
| 272 memcpy(copy->array_, this->array_, this->size_ * sizeof(Unique<T>)); | 287 memcpy(copy->array_, this->array_, this->size_ * sizeof(Unique<T>)); |
| 273 return copy; | 288 return copy; |
| 274 } | 289 } |
| 275 | 290 |
| 291 void Clear() { |
| 292 size_ = 0; |
| 293 } |
| 294 |
| 276 inline int size() const { | 295 inline int size() const { |
| 277 return size_; | 296 return size_; |
| 278 } | 297 } |
| 279 | 298 |
| 280 inline Unique<T> at(int index) const { | 299 inline Unique<T> at(int index) const { |
| 281 ASSERT(index >= 0 && index < size_); | 300 ASSERT(index >= 0 && index < size_); |
| 282 return array_[index]; | 301 return array_[index]; |
| 283 } | 302 } |
| 284 | 303 |
| 285 private: | 304 private: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 304 capacity_ = new_capacity; | 323 capacity_ = new_capacity; |
| 305 array_ = new_array; | 324 array_ = new_array; |
| 306 } | 325 } |
| 307 } | 326 } |
| 308 }; | 327 }; |
| 309 | 328 |
| 310 | 329 |
| 311 } } // namespace v8::internal | 330 } } // namespace v8::internal |
| 312 | 331 |
| 313 #endif // V8_HYDROGEN_UNIQUE_H_ | 332 #endif // V8_HYDROGEN_UNIQUE_H_ |
| OLD | NEW |