OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_IDENTITY_MAP_H_ | 5 #ifndef V8_IDENTITY_MAP_H_ |
6 #define V8_IDENTITY_MAP_H_ | 6 #define V8_IDENTITY_MAP_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 18 matching lines...) Expand all Loading... |
29 zone_(zone), | 29 zone_(zone), |
30 gc_counter_(-1), | 30 gc_counter_(-1), |
31 size_(0), | 31 size_(0), |
32 mask_(0), | 32 mask_(0), |
33 keys_(nullptr), | 33 keys_(nullptr), |
34 values_(nullptr) {} | 34 values_(nullptr) {} |
35 ~IdentityMapBase(); | 35 ~IdentityMapBase(); |
36 | 36 |
37 RawEntry GetEntry(Object* key); | 37 RawEntry GetEntry(Object* key); |
38 RawEntry FindEntry(Object* key); | 38 RawEntry FindEntry(Object* key); |
| 39 void Clear(); |
39 | 40 |
40 private: | 41 private: |
41 // Internal implementation should not be called directly by subclasses. | 42 // Internal implementation should not be called directly by subclasses. |
42 int LookupIndex(Object* address); | 43 int LookupIndex(Object* address); |
43 int InsertIndex(Object* address); | 44 int InsertIndex(Object* address); |
44 void Rehash(); | 45 void Rehash(); |
45 void Resize(); | 46 void Resize(); |
46 RawEntry Lookup(Object* key); | 47 RawEntry Lookup(Object* key); |
47 RawEntry Insert(Object* key); | 48 RawEntry Insert(Object* key); |
48 int Hash(Object* address); | 49 int Hash(Object* address); |
(...skipping 29 matching lines...) Expand all Loading... |
78 // Searches this map for the given key using the object's address | 79 // Searches this map for the given key using the object's address |
79 // as the identity, returning: | 80 // as the identity, returning: |
80 // found => a pointer to the storage location for the value | 81 // found => a pointer to the storage location for the value |
81 // not found => {nullptr} | 82 // not found => {nullptr} |
82 V* Find(Handle<Object> key) { return Find(*key); } | 83 V* Find(Handle<Object> key) { return Find(*key); } |
83 V* Find(Object* key) { return reinterpret_cast<V*>(FindEntry(key)); } | 84 V* Find(Object* key) { return reinterpret_cast<V*>(FindEntry(key)); } |
84 | 85 |
85 // Set the value for the given key. | 86 // Set the value for the given key. |
86 void Set(Handle<Object> key, V v) { Set(*key, v); } | 87 void Set(Handle<Object> key, V v) { Set(*key, v); } |
87 void Set(Object* key, V v) { *(reinterpret_cast<V*>(GetEntry(key))) = v; } | 88 void Set(Object* key, V v) { *(reinterpret_cast<V*>(GetEntry(key))) = v; } |
| 89 |
| 90 // Removes all elements from the map. |
| 91 void Clear() { IdentityMapBase::Clear(); } |
88 }; | 92 }; |
89 } // namespace internal | 93 } // namespace internal |
90 } // namespace v8 | 94 } // namespace v8 |
91 | 95 |
92 #endif // V8_IDENTITY_MAP_H_ | 96 #endif // V8_IDENTITY_MAP_H_ |
OLD | NEW |