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

Side by Side Diff: Source/core/dom/DOMNodeIds.cpp

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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/DOMNodeIds.h ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "config.h" 5 #include "config.h"
6 #include "core/dom/DOMNodeIds.h" 6 #include "core/dom/DOMNodeIds.h"
7
8 #if ENABLE(OILPAN)
9 #include "core/dom/Node.h" 7 #include "core/dom/Node.h"
10 #else
11 #include "core/dom/WeakNodeMap.h"
12 #endif
13 #include "platform/heap/Handle.h" 8 #include "platform/heap/Handle.h"
14 9
15 namespace blink { 10 namespace blink {
16 11
17 #if ENABLE(OILPAN) 12 #if !ENABLE(OILPAN)
18 typedef HeapHashMap<WeakMember<Node>, int> NodeToIdMap; 13 void WeakIdentifierMapTraits<Node>::removedFromIdentifierMap(Node* node)
19 typedef HeapHashMap<int, WeakMember<Node>> IdToNodeMap;
20
21 static NodeToIdMap& nodeToIdMap()
22 { 14 {
23 DEFINE_STATIC_LOCAL(Persistent<NodeToIdMap>, nodeToIdMap, (new NodeToIdMap() )); 15 node->clearFlag(Node::HasWeakReferencesFlag);
24 return *nodeToIdMap;
25 } 16 }
26 17
27 static IdToNodeMap& idToNodeMap() 18 void WeakIdentifierMapTraits<Node>::addedToIdentifierMap(Node* node)
28 { 19 {
29 DEFINE_STATIC_LOCAL(Persistent<IdToNodeMap>, idToNodeMap, (new IdToNodeMap() )); 20 node->setFlag(Node::HasWeakReferencesFlag);
30 return *idToNodeMap; 21 }
22 #endif
23
24 static WeakNodeMap& nodeIds()
25 {
26 DEFINE_STATIC_LOCAL(RawPtrWillBePersistent<WeakNodeMap>, self, (new WeakNode Map()));
27 return *self;
31 } 28 }
32 29
33 int DOMNodeIds::idForNode(Node* node) 30 int DOMNodeIds::idForNode(Node* node)
34 { 31 {
35 static int s_nextNodeId = 1; 32 return nodeIds().identifier(node);
36 NodeToIdMap::iterator it = nodeToIdMap().find(node);
37 if (it != nodeToIdMap().end())
38 return it->value;
39 int id = s_nextNodeId++;
40 nodeToIdMap().set(node, id);
41 ASSERT(idToNodeMap().find(id) == idToNodeMap().end());
42 idToNodeMap().set(id, node);
43 return id;
44 }
45
46 Node* DOMNodeIds::nodeForId(int id)
47 {
48 return idToNodeMap().get(id);
49 }
50 #else
51 static WeakNodeMap& nodeIds()
52 {
53 DEFINE_STATIC_LOCAL(WeakNodeMap, self, ());
54 return self;
55 }
56
57 int DOMNodeIds::idForNode(Node* node)
58 {
59 static int s_nextNodeId = 1;
60 WeakNodeMap& ids = nodeIds();
61 int result = ids.identifier(node);
62 if (!result) {
63 result = s_nextNodeId++;
64 ids.put(node, result);
65 }
66 return result;
67 } 33 }
68 34
69 Node* DOMNodeIds::nodeForId(int id) 35 Node* DOMNodeIds::nodeForId(int id)
70 { 36 {
71 return nodeIds().lookup(id); 37 return nodeIds().lookup(id);
72 } 38 }
73 #endif
74 39
75 } 40 }
OLDNEW
« no previous file with comments | « Source/core/dom/DOMNodeIds.h ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698