| 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>>
; |
| 42 | 43 |
| 43 static IdentifierType identifier(T* object) | 44 static IdentifierType identifier(T* object) |
| 44 { | 45 { |
| 45 IdentifierType result = instance().m_objectToIdentifier.get(object); | 46 IdentifierType result = instance().m_objectToIdentifier.get(object); |
| 46 | 47 |
| 47 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { | 48 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { |
| 48 result = Generator::next(); | 49 result = Generator::next(); |
| 49 instance().put(object, result); | 50 instance().put(object, result); |
| 50 } | 51 } |
| 51 return result; | 52 return result; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 using IdentifierToObject = HashMap<IdentifierType, T*>; | 86 using IdentifierToObject = HashMap<IdentifierType, T*>; |
| 86 | 87 |
| 87 ObjectToIdentifier m_objectToIdentifier; | 88 ObjectToIdentifier m_objectToIdentifier; |
| 88 IdentifierToObject m_identifierToObject; | 89 IdentifierToObject m_identifierToObject; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, true> | 92 template<typename T, typename Generator, typename Traits> class WeakIdentifierMa
p<T, Generator, Traits, true> |
| 92 : public GarbageCollected<WeakIdentifierMap<T, Generator, Traits, true>> { | 93 : public GarbageCollected<WeakIdentifierMap<T, Generator, Traits, true>> { |
| 93 public: | 94 public: |
| 94 using IdentifierType = typename Generator::IdentifierType; | 95 using IdentifierType = typename Generator::IdentifierType; |
| 96 using ReferenceType = Persistent<WeakIdentifierMap<T, Generator, Traits, tru
e>>; |
| 95 | 97 |
| 96 static IdentifierType identifier(T* object) | 98 static IdentifierType identifier(T* object) |
| 97 { | 99 { |
| 98 IdentifierType result = instance().m_objectToIdentifier->get(object); | 100 IdentifierType result = instance().m_objectToIdentifier->get(object); |
| 99 | 101 |
| 100 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { | 102 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { |
| 101 result = Generator::next(); | 103 result = Generator::next(); |
| 102 instance().put(object, result); | 104 instance().put(object, result); |
| 103 } | 105 } |
| 104 return result; | 106 return result; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; | 139 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; |
| 138 | 140 |
| 139 Member<ObjectToIdentifier> m_objectToIdentifier; | 141 Member<ObjectToIdentifier> m_objectToIdentifier; |
| 140 Member<IdentifierToObject> m_identifierToObject; | 142 Member<IdentifierToObject> m_identifierToObject; |
| 141 }; | 143 }; |
| 142 | 144 |
| 143 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ | 145 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ |
| 144 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ | 146 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ |
| 145 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; | 147 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; |
| 146 | 148 |
| 147 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ | 149 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ |
| 148 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 150 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
| 149 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ | 151 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ |
| 150 { \ | 152 { \ |
| 151 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 153 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>::ReferenceType; \ |
| 152 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ | 154 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ |
| 153 return mapInstance; \ | 155 return *mapInstance; \ |
| 154 } | 156 } |
| 155 | |
| 156 } // namespace blink | 157 } // namespace blink |
| 157 | 158 |
| 158 #endif // WeakIdentifierMap_h | 159 #endif // WeakIdentifierMap_h |
| OLD | NEW |