| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 instance().objectDestroyed(object); | 61 instance().objectDestroyed(object); |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 static WeakIdentifierMap<T, Generator, Traits>& instance(); | 65 static WeakIdentifierMap<T, Generator, Traits>& instance(); |
| 66 WeakIdentifierMap() { } | 66 WeakIdentifierMap() { } |
| 67 ~WeakIdentifierMap(); | 67 ~WeakIdentifierMap(); |
| 68 | 68 |
| 69 void put(T* object, IdentifierType identifier) | 69 void put(T* object, IdentifierType identifier) |
| 70 { | 70 { |
| 71 ASSERT(object && !m_objectToIdentifier.contains(object)); | 71 DCHECK(object && !m_objectToIdentifier.contains(object)); |
| 72 m_objectToIdentifier.set(object, identifier); | 72 m_objectToIdentifier.set(object, identifier); |
| 73 m_identifierToObject.set(identifier, object); | 73 m_identifierToObject.set(identifier, object); |
| 74 Traits::addedToIdentifierMap(object); | 74 Traits::addedToIdentifierMap(object); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void objectDestroyed(T* object) | 77 void objectDestroyed(T* object) |
| 78 { | 78 { |
| 79 IdentifierType identifier = m_objectToIdentifier.take(object); | 79 IdentifierType identifier = m_objectToIdentifier.take(object); |
| 80 if (!WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(identifier)
) | 80 if (!WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(identifier)
) |
| 81 m_identifierToObject.remove(identifier); | 81 m_identifierToObject.remove(identifier); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 static WeakIdentifierMap<T, Generator, Traits>& instance(); | 121 static WeakIdentifierMap<T, Generator, Traits>& instance(); |
| 122 | 122 |
| 123 WeakIdentifierMap() | 123 WeakIdentifierMap() |
| 124 : m_objectToIdentifier(new ObjectToIdentifier()) | 124 : m_objectToIdentifier(new ObjectToIdentifier()) |
| 125 , m_identifierToObject(new IdentifierToObject()) | 125 , m_identifierToObject(new IdentifierToObject()) |
| 126 { | 126 { |
| 127 } | 127 } |
| 128 | 128 |
| 129 void put(T* object, IdentifierType identifier) | 129 void put(T* object, IdentifierType identifier) |
| 130 { | 130 { |
| 131 ASSERT(object && !m_objectToIdentifier->contains(object)); | 131 DCHECK(object && !m_objectToIdentifier->contains(object)); |
| 132 m_objectToIdentifier->set(object, identifier); | 132 m_objectToIdentifier->set(object, identifier); |
| 133 m_identifierToObject->set(identifier, object); | 133 m_identifierToObject->set(identifier, object); |
| 134 } | 134 } |
| 135 | 135 |
| 136 using ObjectToIdentifier = HeapHashMap<WeakMember<T>, IdentifierType>; | 136 using ObjectToIdentifier = HeapHashMap<WeakMember<T>, IdentifierType>; |
| 137 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; | 137 using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>; |
| 138 | 138 |
| 139 Member<ObjectToIdentifier> m_objectToIdentifier; | 139 Member<ObjectToIdentifier> m_objectToIdentifier; |
| 140 Member<IdentifierToObject> m_identifierToObject; | 140 Member<IdentifierToObject> m_identifierToObject; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ | 143 #define DECLARE_WEAK_IDENTIFIER_MAP(T, ...) \ |
| 144 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ | 144 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance(); \ |
| 145 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; | 145 extern template class WeakIdentifierMap<T, ##__VA_ARGS__>; |
| 146 | 146 |
| 147 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ | 147 #define DEFINE_WEAK_IDENTIFIER_MAP(T, ...) \ |
| 148 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 148 template class WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
| 149 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ | 149 template<> WeakIdentifierMap<T, ##__VA_ARGS__>& WeakIdentifierMap<T, ##__VA_
ARGS__>::instance() \ |
| 150 { \ | 150 { \ |
| 151 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 151 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
| 152 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ | 152 DEFINE_STATIC_LOCAL(RefType, mapInstance, (new WeakIdentifierMap<T, ##__
VA_ARGS__>())); \ |
| 153 return mapInstance; \ | 153 return mapInstance; \ |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| 157 | 157 |
| 158 #endif // WeakIdentifierMap_h | 158 #endif // WeakIdentifierMap_h |
| OLD | NEW |