Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: Source/core/dom/WeakIdentifierMap.h

Issue 1085033003: Introduce InspectorIdentifiers<> and use it to assign/lookup LocalFrame and DocumentLoader (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: win build error fixed Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/frame/LocalFrame.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/WeakIdentifierMap.h
diff --git a/Source/core/dom/WeakIdentifierMap.h b/Source/core/dom/WeakIdentifierMap.h
index 8a04aa8812d0a8033bc4af59fe0ccb3e2cf277d5..24e55f083e6faa20a84621d5ff56560d3f2421dc 100644
--- a/Source/core/dom/WeakIdentifierMap.h
+++ b/Source/core/dom/WeakIdentifierMap.h
@@ -11,14 +11,32 @@
namespace blink {
-#if !ENABLE(OILPAN)
+template<typename T> struct IdentifierGenerator;
+
+template<> struct IdentifierGenerator<int> {
+ using IdentifierType = int;
+ static IdentifierType next()
+ {
+ static int s_lastId = 0;
+ return ++s_lastId;
+ }
+};
+
template<typename T> struct WeakIdentifierMapTraits {
static void removedFromIdentifierMap(T*) { }
static void addedToIdentifierMap(T*) { }
};
-template<typename T, typename Traits = WeakIdentifierMapTraits<T>> class WeakIdentifierMap {
+template<typename T,
+ typename Generator = IdentifierGenerator<int>,
+ typename Traits = WeakIdentifierMapTraits<T>,
+ bool isGarbageCollected = IsGarbageCollectedType<T>::value> class WeakIdentifierMap;
+
+template<typename T, typename Generator, typename Traits> class WeakIdentifierMap<T, Generator, Traits, false> {
public:
+ using IdentifierType = typename Generator::IdentifierType;
+ using ReferenceType = RawPtr<WeakIdentifierMap<T, Generator, Traits, false>>;
+
~WeakIdentifierMap()
{
ObjectToWeakIdentifierMaps& allMaps = ObjectToWeakIdentifierMaps::instance();
@@ -29,18 +47,18 @@ public:
}
}
- int identifier(T* object)
+ IdentifierType identifier(T* object)
{
- int result = m_objectToIdentifier.get(object);
- if (!result) {
- static int s_lastId = 0;
- result = ++s_lastId;
+ IdentifierType result = m_objectToIdentifier.get(object);
+
+ if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) {
+ result = Generator::next();
put(object, result);
}
return result;
}
- T* lookup(int identifier)
+ T* lookup(IdentifierType identifier)
{
return m_identifierToObject.get(identifier);
}
@@ -51,7 +69,7 @@ public:
}
private:
- void put(T* object, int identifier)
+ void put(T* object, IdentifierType identifier)
{
ASSERT(object && !m_objectToIdentifier.contains(object));
m_objectToIdentifier.set(object, identifier);
@@ -63,7 +81,7 @@ private:
}
class ObjectToWeakIdentifierMaps {
- typedef WeakIdentifierMap<T> IdentifierMap;
+ using IdentifierMap = WeakIdentifierMap<T, Generator, Traits>;
public:
bool addedToMap(T* object, IdentifierMap* map)
{
@@ -91,9 +109,10 @@ private:
void objectDestroyed(T* object)
{
- OwnPtr<MapList> maps = m_objectToMapList.take(object);
- for (auto& map : *maps)
- map->objectDestroyed(object);
+ if (OwnPtr<MapList> maps = m_objectToMapList.take(object)) {
+ for (auto& map : *maps)
+ map->objectDestroyed(object);
+ }
}
static ObjectToWeakIdentifierMaps& instance()
@@ -103,8 +122,8 @@ private:
}
private:
- typedef Vector<IdentifierMap*, 1> MapList;
- typedef HashMap<T*, OwnPtr<MapList>> ObjectToMapList;
+ using MapList = Vector<IdentifierMap*, 1>;
+ using ObjectToMapList = HashMap<T*, OwnPtr<MapList>>;
ObjectToMapList m_objectToMapList;
};
@@ -115,35 +134,37 @@ private:
m_identifierToObject.remove(identifier);
}
- typedef HashMap<T*, int> ObjectToIdentifier;
- typedef HashMap<int, T*> IdentifierToObject;
+ using ObjectToIdentifier = HashMap<T*, IdentifierType>;
+ using IdentifierToObject = HashMap<IdentifierType, T*>;
ObjectToIdentifier m_objectToIdentifier;
IdentifierToObject m_identifierToObject;
};
-#else // ENABLE(OILPAN)
-
-template<typename T> class WeakIdentifierMap : public GarbageCollected<WeakIdentifierMap<T>> {
+template<typename T, typename Generator, typename Traits> class WeakIdentifierMap<T, Generator, Traits, true>
+ : public GarbageCollected<WeakIdentifierMap<T, Generator, Traits, true>> {
public:
+ using IdentifierType = typename Generator::IdentifierType;
+ using ReferenceType = Persistent<WeakIdentifierMap<T, Generator, Traits, true>>;
+
WeakIdentifierMap()
: m_objectToIdentifier(new ObjectToIdentifier())
, m_identifierToObject(new IdentifierToObject())
{
}
- int identifier(T* object)
+ IdentifierType identifier(T* object)
{
- int result = m_objectToIdentifier->get(object);
- if (!result) {
- static int s_lastId = 0;
- result = ++s_lastId;
+ IdentifierType result = m_objectToIdentifier->get(object);
+
+ if (WTF::isHashTraitsEmptyValue<HashTraits<IdentifierType>>(result)) {
+ result = Generator::next();
put(object, result);
}
return result;
}
- T* lookup(int identifier)
+ T* lookup(IdentifierType identifier)
{
return m_identifierToObject->get(identifier);
}
@@ -157,22 +178,20 @@ public:
}
private:
- void put(T* object, int identifier)
+ void put(T* object, IdentifierType identifier)
{
ASSERT(object && !m_objectToIdentifier->contains(object));
m_objectToIdentifier->set(object, identifier);
m_identifierToObject->set(identifier, object);
}
- typedef HeapHashMap<WeakMember<T>, int> ObjectToIdentifier;
- typedef HeapHashMap<int, WeakMember<T>> IdentifierToObject;
+ using ObjectToIdentifier = HeapHashMap<WeakMember<T>, IdentifierType>;
+ using IdentifierToObject = HeapHashMap<IdentifierType, WeakMember<T>>;
Member<ObjectToIdentifier> m_objectToIdentifier;
Member<IdentifierToObject> m_identifierToObject;
};
-#endif // ENABLE(OILPAN)
-
}
#endif // WeakIdentifierMap_h
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/frame/LocalFrame.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698