OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 WeakIdentifierMap_h | 5 #ifndef WeakIdentifierMap_h |
6 #define WeakIdentifierMap_h | 6 #define WeakIdentifierMap_h |
7 | 7 |
8 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/HashMap.h" | 10 #include "wtf/HashMap.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 template<typename T, | 33 template<typename T, |
34 typename Generator = IdentifierGenerator<int>, | 34 typename Generator = IdentifierGenerator<int>, |
35 typename Traits = WeakIdentifierMapTraits<T>, | 35 typename Traits = WeakIdentifierMapTraits<T>, |
36 bool isGarbageCollected = IsGarbageCollectedType<T>::value> class WeakIdenti
fierMap; | 36 bool isGarbageCollected = IsGarbageCollectedType<T>::value> class WeakIdenti
fierMap; |
37 | 37 |
38 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, false> { | 38 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, false> { |
39 USING_FAST_MALLOC(WeakIdentifierMap); | 39 USING_FAST_MALLOC(WeakIdentifierMap); |
40 public: | 40 public: |
41 using IdentifierType = typename Generator::IdentifierType; | 41 using IdentifierType = typename Generator::IdentifierType; |
42 using ReferenceType = RawPtr<WeakIdentifierMap<T, Generator, Traits, false>>
; | |
43 | 42 |
44 static IdentifierType identifier(T* object) | 43 static IdentifierType identifier(T* object) |
45 { | 44 { |
46 IdentifierType result = instance().m_objectToIdentifier.get(object); | 45 IdentifierType result = instance().m_objectToIdentifier.get(object); |
47 | 46 |
48 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { | 47 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { |
49 result = Generator::next(); | 48 result = Generator::next(); |
50 instance().put(object, result); | 49 instance().put(object, result); |
51 } | 50 } |
52 return result; | 51 return result; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 using IdentifierToObject = HashMap<IdentifierType, T*>; | 85 using IdentifierToObject = HashMap<IdentifierType, T*>; |
87 | 86 |
88 ObjectToIdentifier m_objectToIdentifier; | 87 ObjectToIdentifier m_objectToIdentifier; |
89 IdentifierToObject m_identifierToObject; | 88 IdentifierToObject m_identifierToObject; |
90 }; | 89 }; |
91 | 90 |
92 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, true> | 91 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, true> |
93 : public GarbageCollected<WeakIdentifierMap<T, Generator, Traits, true>> { | 92 : public GarbageCollected<WeakIdentifierMap<T, Generator, Traits, true>> { |
94 public: | 93 public: |
95 using IdentifierType = typename Generator::IdentifierType; | 94 using IdentifierType = typename Generator::IdentifierType; |
96 using ReferenceType = Persistent<WeakIdentifierMap<T, Generator, Traits, tru
e>>; | |
97 | 95 |
98 static IdentifierType identifier(T* object) | 96 static IdentifierType identifier(T* object) |
99 { | 97 { |
100 IdentifierType result = instance().m_objectToIdentifier->get(object); | 98 IdentifierType result = instance().m_objectToIdentifier->get(object); |
101 | 99 |
102 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { | 100 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { |
103 result = Generator::next(); | 101 result = Generator::next(); |
104 instance().put(object, result); | 102 instance().put(object, result); |
105 } | 103 } |
106 return result; | 104 return result; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; | 137 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; |
140 | 138 |
141 Member<ObjectToIdentifier> m_objectToIdentifier; | 139 Member<ObjectToIdentifier> m_objectToIdentifier; |
142 Member<IdentifierToObject> m_identifierToObject; | 140 Member<IdentifierToObject> m_identifierToObject; |
143 }; | 141 }; |
144 | 142 |
145 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ | 143 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ |
146 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ | 144 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ |
147 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; | 145 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; |
148 | 146 |
149 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ | 147 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ |
150 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 148 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
151 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ | 149 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ |
152 { \ | 150 { \ |
153 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>::ReferenceType; \ | 151 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
154 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ | 152 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ |
155 return *mapInstance; \ | 153 return mapInstance; \ |
156 } | 154 } |
| 155 |
157 } // namespace blink | 156 } // namespace blink |
158 | 157 |
159 #endif // WeakIdentifierMap_h | 158 #endif // WeakIdentifierMap_h |
OLD | NEW |