OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 7215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7226 RawSmi* deleted_keys() const { | 7226 RawSmi* deleted_keys() const { |
7227 return raw_ptr()->deleted_keys_; | 7227 return raw_ptr()->deleted_keys_; |
7228 } | 7228 } |
7229 void SetDeletedKeys(intptr_t value) const { | 7229 void SetDeletedKeys(intptr_t value) const { |
7230 StoreSmi(&raw_ptr()->deleted_keys_, Smi::New(value)); | 7230 StoreSmi(&raw_ptr()->deleted_keys_, Smi::New(value)); |
7231 } | 7231 } |
7232 static intptr_t deleted_keys_offset() { | 7232 static intptr_t deleted_keys_offset() { |
7233 return OFFSET_OF(RawLinkedHashMap, deleted_keys_); | 7233 return OFFSET_OF(RawLinkedHashMap, deleted_keys_); |
7234 } | 7234 } |
7235 | 7235 |
| 7236 intptr_t Length() const { |
| 7237 intptr_t used = Smi::Value(raw_ptr()->used_data_); |
| 7238 intptr_t deleted = Smi::Value(raw_ptr()->deleted_keys_); |
| 7239 return (used >> 1) - deleted; |
| 7240 } |
| 7241 |
| 7242 // This iterator differs somewhat from its Dart counterpart (_CompactIterator |
| 7243 // in runtime/lib/compact_hash.dart): |
| 7244 // - There are no checks for concurrent modifications. |
| 7245 // - Accessing a key or value before the first call to MoveNext and after |
| 7246 // MoveNext returns false will result in crashes. |
| 7247 class Iterator : ValueObject { |
| 7248 public: |
| 7249 explicit Iterator(const LinkedHashMap& map) |
| 7250 : map_(map), |
| 7251 data_(Array::Handle(map.data())), |
| 7252 scratch_(Object::Handle()), |
| 7253 offset_(-2), |
| 7254 length_(Smi::Value(map.used_data())) {} |
| 7255 |
| 7256 bool MoveNext() { |
| 7257 while (true) { |
| 7258 offset_ += 2; |
| 7259 if (offset_ >= length_) { |
| 7260 return false; |
| 7261 } |
| 7262 scratch_ = data_.At(offset_); |
| 7263 if (scratch_.raw() != data_.raw()) { |
| 7264 // Slot is not deleted (self-reference indicates deletion). |
| 7265 return true; |
| 7266 } |
| 7267 } |
| 7268 } |
| 7269 |
| 7270 RawObject* CurrentKey() const { |
| 7271 return data_.At(offset_); |
| 7272 } |
| 7273 |
| 7274 RawObject* CurrentValue() const { |
| 7275 return data_.At(offset_ + 1); |
| 7276 } |
| 7277 |
| 7278 private: |
| 7279 const LinkedHashMap& map_; |
| 7280 const Array& data_; |
| 7281 Object& scratch_; |
| 7282 intptr_t offset_; |
| 7283 const intptr_t length_; |
| 7284 }; |
| 7285 |
7236 private: | 7286 private: |
7237 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance); | 7287 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance); |
7238 | 7288 |
7239 // Keep this in sync with Dart implementation (lib/compact_hash.dart). | 7289 // Keep this in sync with Dart implementation (lib/compact_hash.dart). |
7240 static const intptr_t kInitialIndexBits = 3; | 7290 static const intptr_t kInitialIndexBits = 3; |
7241 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); | 7291 static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); |
7242 | 7292 |
7243 // Allocate a map, but leave all fields set to null. | 7293 // Allocate a map, but leave all fields set to null. |
7244 // Used during deserialization (since map might contain itself as key/value). | 7294 // Used during deserialization (since map might contain itself as key/value). |
7245 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); | 7295 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7796 | 7846 |
7797 | 7847 |
7798 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7848 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7799 intptr_t index) { | 7849 intptr_t index) { |
7800 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7850 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7801 } | 7851 } |
7802 | 7852 |
7803 } // namespace dart | 7853 } // namespace dart |
7804 | 7854 |
7805 #endif // VM_OBJECT_H_ | 7855 #endif // VM_OBJECT_H_ |
OLD | NEW |