| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 IdentifierToObject m_identifierToObject; | 43 IdentifierToObject m_identifierToObject; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 template <typename T, typename IdentifierType = int> | 46 template <typename T, typename IdentifierType = int> |
| 47 class WeakIdentifierMap final | 47 class WeakIdentifierMap final |
| 48 : public WeakIdentifierMapBase<T, | 48 : public WeakIdentifierMapBase<T, |
| 49 IdentifierType, | 49 IdentifierType, |
| 50 IsGarbageCollectedType<T>::value> { | 50 IsGarbageCollectedType<T>::value> { |
| 51 public: | 51 public: |
| 52 static IdentifierType identifier(T* object) { | 52 static IdentifierType identifier(T* object) { |
| 53 IdentifierType result = instance().m_objectToIdentifier.get(object); | 53 IdentifierType result = instance().m_objectToIdentifier.at(object); |
| 54 | 54 |
| 55 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { | 55 if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) { |
| 56 result = next(); | 56 result = next(); |
| 57 instance().put(object, result); | 57 instance().put(object, result); |
| 58 } | 58 } |
| 59 return result; | 59 return result; |
| 60 } | 60 } |
| 61 | 61 |
| 62 static T* lookup(IdentifierType identifier) { | 62 static T* lookup(IdentifierType identifier) { |
| 63 return instance().m_identifierToObject.get(identifier); | 63 return instance().m_identifierToObject.at(identifier); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static void notifyObjectDestroyed(T* object) { | 66 static void notifyObjectDestroyed(T* object) { |
| 67 instance().objectDestroyed(object); | 67 instance().objectDestroyed(object); |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 static WeakIdentifierMap<T, IdentifierType>& instance(); | 71 static WeakIdentifierMap<T, IdentifierType>& instance(); |
| 72 | 72 |
| 73 WeakIdentifierMap() {} | 73 WeakIdentifierMap() {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 103 WeakIdentifierMap<T, ##__VA_ARGS__>::instance() { \ | 103 WeakIdentifierMap<T, ##__VA_ARGS__>::instance() { \ |
| 104 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ | 104 using RefType = WeakIdentifierMap<T, ##__VA_ARGS__>; \ |
| 105 DEFINE_STATIC_LOCAL(RefType, mapInstance, \ | 105 DEFINE_STATIC_LOCAL(RefType, mapInstance, \ |
| 106 (new WeakIdentifierMap<T, ##__VA_ARGS__>())); \ | 106 (new WeakIdentifierMap<T, ##__VA_ARGS__>())); \ |
| 107 return mapInstance; \ | 107 return mapInstance; \ |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace blink | 110 } // namespace blink |
| 111 | 111 |
| 112 #endif // WeakIdentifierMap_h | 112 #endif // WeakIdentifierMap_h |
| OLD | NEW |