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 class Iterator : ValueObject { | |
koda
2015/06/02 16:42:37
Add comment to note how this differs from its Dart
rmacnak
2015/06/02 17:33:31
Done.
| |
7243 public: | |
7244 explicit Iterator(const LinkedHashMap& map) | |
7245 : map_(map) | |
7246 , data_(Array::Handle(map.data())) | |
koda
2015/06/02 16:42:37
I think our code usually has these commas at the e
rmacnak
2015/06/02 17:33:31
Ah, yes. Before is Blink.
| |
7247 , scratch_(Object::Handle()) | |
7248 , offset_(-2) | |
7249 , length_(Smi::Handle(map.used_data()).Value()) {} | |
koda
2015/06/02 16:42:37
Avoid handle creation: Smi::Value(map.used_data())
rmacnak
2015/06/02 17:33:31
Done.
| |
7250 | |
7251 bool MoveNext() { | |
7252 // Cf. _CompactIterator in runtime/lib/compact_hash.dart. | |
7253 while (true) { | |
7254 offset_ += 2; | |
7255 if (offset_ >= length_) { | |
7256 return false; | |
7257 } | |
7258 scratch_ = data_.At(offset_); | |
7259 if (scratch_.raw() != data_.raw()) { | |
7260 // Slot is not deleted (self-reference indicates deletion). | |
7261 return true; | |
7262 } | |
7263 } | |
7264 } | |
7265 | |
7266 RawObject* CurrentKey() const { | |
7267 return data_.At(offset_); | |
7268 } | |
7269 | |
7270 RawObject* CurrentValue() const { | |
7271 return data_.At(offset_ + 1); | |
7272 } | |
7273 | |
7274 private: | |
7275 const LinkedHashMap& map_; | |
7276 const Array& data_; | |
7277 Object& scratch_; | |
7278 intptr_t offset_; | |
7279 const intptr_t length_; | |
7280 }; | |
7281 | |
7236 private: | 7282 private: |
7237 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance); | 7283 FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance); |
7238 | 7284 |
7239 // Allocate a map, but leave all fields set to null. | 7285 // Allocate a map, but leave all fields set to null. |
7240 // Used during deserialization (since map might contain itself as key/value). | 7286 // Used during deserialization (since map might contain itself as key/value). |
7241 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); | 7287 static RawLinkedHashMap* NewUninitialized(Heap::Space space = Heap::kNew); |
7242 | 7288 |
7243 friend class Class; | 7289 friend class Class; |
7244 }; | 7290 }; |
7245 | 7291 |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7792 | 7838 |
7793 | 7839 |
7794 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 7840 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
7795 intptr_t index) { | 7841 intptr_t index) { |
7796 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 7842 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
7797 } | 7843 } |
7798 | 7844 |
7799 } // namespace dart | 7845 } // namespace dart |
7800 | 7846 |
7801 #endif // VM_OBJECT_H_ | 7847 #endif // VM_OBJECT_H_ |
OLD | NEW |