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

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

Issue 1089933004: DevTools: make DOMNodeIds a trivial wrapper around WeakIdentifierMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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.cpp ('k') | Source/core/dom/WeakNodeMap.h » ('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 8dd2c9555e96199855d0a543174eaf04f988cf27..8a04aa8812d0a8033bc4af59fe0ccb3e2cf277d5 100644
--- a/Source/core/dom/WeakIdentifierMap.h
+++ b/Source/core/dom/WeakIdentifierMap.h
@@ -5,9 +5,13 @@
#ifndef WeakIdentifierMap_h
#define WeakIdentifierMap_h
+#include "platform/heap/Handle.h"
#include "wtf/HashMap.h"
+#include "wtf/Vector.h"
namespace blink {
+
+#if !ENABLE(OILPAN)
template<typename T> struct WeakIdentifierMapTraits {
static void removedFromIdentifierMap(T*) { }
static void addedToIdentifierMap(T*) { }
@@ -25,20 +29,15 @@ public:
}
}
- void put(T* object, int identifier)
- {
- ASSERT(object && !m_objectToIdentifier.contains(object));
- m_objectToIdentifier.set(object, identifier);
- m_identifierToObject.set(identifier, object);
-
- ObjectToWeakIdentifierMaps& maps = ObjectToWeakIdentifierMaps::instance();
- if (maps.addedToMap(object, this))
- Traits::addedToIdentifierMap(object);
- }
-
int identifier(T* object)
{
- return m_objectToIdentifier.get(object);
+ int result = m_objectToIdentifier.get(object);
+ if (!result) {
+ static int s_lastId = 0;
+ result = ++s_lastId;
+ put(object, result);
+ }
+ return result;
}
T* lookup(int identifier)
@@ -52,6 +51,17 @@ public:
}
private:
+ void put(T* object, int identifier)
+ {
+ ASSERT(object && !m_objectToIdentifier.contains(object));
+ m_objectToIdentifier.set(object, identifier);
+ m_identifierToObject.set(identifier, object);
+
+ ObjectToWeakIdentifierMaps& maps = ObjectToWeakIdentifierMaps::instance();
+ if (maps.addedToMap(object, this))
+ Traits::addedToIdentifierMap(object);
+ }
+
class ObjectToWeakIdentifierMaps {
typedef WeakIdentifierMap<T> IdentifierMap;
public:
@@ -106,10 +116,63 @@ private:
}
typedef HashMap<T*, int> ObjectToIdentifier;
- ObjectToIdentifier m_objectToIdentifier;
typedef HashMap<int, T*> IdentifierToObject;
+
+ ObjectToIdentifier m_objectToIdentifier;
IdentifierToObject m_identifierToObject;
};
+#else // ENABLE(OILPAN)
+
+template<typename T> class WeakIdentifierMap : public GarbageCollected<WeakIdentifierMap<T>> {
+public:
+ WeakIdentifierMap()
+ : m_objectToIdentifier(new ObjectToIdentifier())
+ , m_identifierToObject(new IdentifierToObject())
+ {
+ }
+
+ int identifier(T* object)
+ {
+ int result = m_objectToIdentifier->get(object);
+ if (!result) {
+ static int s_lastId = 0;
+ result = ++s_lastId;
+ put(object, result);
+ }
+ return result;
+ }
+
+ T* lookup(int identifier)
+ {
+ return m_identifierToObject->get(identifier);
+ }
+
+ static void notifyObjectDestroyed(T* object) { }
+
+ DEFINE_INLINE_TRACE()
+ {
+ visitor->trace(m_objectToIdentifier);
+ visitor->trace(m_identifierToObject);
+ }
+
+private:
+ void put(T* object, int 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;
+
+ Member<ObjectToIdentifier> m_objectToIdentifier;
+ Member<IdentifierToObject> m_identifierToObject;
+};
+
+#endif // ENABLE(OILPAN)
+
}
+
#endif // WeakIdentifierMap_h
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/WeakNodeMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698