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 RUNTIME_VM_OBJECT_H_ | 5 #ifndef RUNTIME_VM_OBJECT_H_ |
6 #define RUNTIME_VM_OBJECT_H_ | 6 #define RUNTIME_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 8182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8193 | 8193 |
8194 RawSmi* deleted_keys() const { return raw_ptr()->deleted_keys_; } | 8194 RawSmi* deleted_keys() const { return raw_ptr()->deleted_keys_; } |
8195 void SetDeletedKeys(intptr_t value) const { | 8195 void SetDeletedKeys(intptr_t value) const { |
8196 StoreSmi(&raw_ptr()->deleted_keys_, Smi::New(value)); | 8196 StoreSmi(&raw_ptr()->deleted_keys_, Smi::New(value)); |
8197 } | 8197 } |
8198 static intptr_t deleted_keys_offset() { | 8198 static intptr_t deleted_keys_offset() { |
8199 return OFFSET_OF(RawLinkedHashMap, deleted_keys_); | 8199 return OFFSET_OF(RawLinkedHashMap, deleted_keys_); |
8200 } | 8200 } |
8201 | 8201 |
8202 intptr_t Length() const { | 8202 intptr_t Length() const { |
| 8203 // The map may be uninitialized. |
| 8204 if (raw_ptr()->used_data_ == Object::null()) return 0; |
| 8205 if (raw_ptr()->deleted_keys_ == Object::null()) return 0; |
| 8206 |
8203 intptr_t used = Smi::Value(raw_ptr()->used_data_); | 8207 intptr_t used = Smi::Value(raw_ptr()->used_data_); |
8204 intptr_t deleted = Smi::Value(raw_ptr()->deleted_keys_); | 8208 intptr_t deleted = Smi::Value(raw_ptr()->deleted_keys_); |
8205 return (used >> 1) - deleted; | 8209 return (used >> 1) - deleted; |
8206 } | 8210 } |
8207 | 8211 |
8208 // This iterator differs somewhat from its Dart counterpart (_CompactIterator | 8212 // This iterator differs somewhat from its Dart counterpart (_CompactIterator |
8209 // in runtime/lib/compact_hash.dart): | 8213 // in runtime/lib/compact_hash.dart): |
8210 // - There are no checks for concurrent modifications. | 8214 // - There are no checks for concurrent modifications. |
8211 // - Accessing a key or value before the first call to MoveNext and after | 8215 // - Accessing a key or value before the first call to MoveNext and after |
8212 // MoveNext returns false will result in crashes. | 8216 // MoveNext returns false will result in crashes. |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8832 | 8836 |
8833 inline void TypeArguments::SetHash(intptr_t value) const { | 8837 inline void TypeArguments::SetHash(intptr_t value) const { |
8834 // This is only safe because we create a new Smi, which does not cause | 8838 // This is only safe because we create a new Smi, which does not cause |
8835 // heap allocation. | 8839 // heap allocation. |
8836 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8840 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
8837 } | 8841 } |
8838 | 8842 |
8839 } // namespace dart | 8843 } // namespace dart |
8840 | 8844 |
8841 #endif // RUNTIME_VM_OBJECT_H_ | 8845 #endif // RUNTIME_VM_OBJECT_H_ |
OLD | NEW |