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

Side by Side Diff: Source/core/dom/NodeRareData.h

Issue 176933013: Pass rootNode by reference when constructing node lists / collections (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 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/Node.cpp ('k') | Source/core/dom/TagCollection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com> 3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 class NodeListsNodeData { 44 class NodeListsNodeData {
45 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; 45 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED;
46 public: 46 public:
47 void clearChildNodeListCache() 47 void clearChildNodeListCache()
48 { 48 {
49 if (m_childNodeList && m_childNodeList->isChildNodeList()) 49 if (m_childNodeList && m_childNodeList->isChildNodeList())
50 toChildNodeList(m_childNodeList)->invalidateCache(); 50 toChildNodeList(m_childNodeList)->invalidateCache();
51 } 51 }
52 52
53 PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode* node) 53 PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode& node)
54 { 54 {
55 if (m_childNodeList) 55 if (m_childNodeList)
56 return toChildNodeList(m_childNodeList); 56 return toChildNodeList(m_childNodeList);
57 RefPtr<ChildNodeList> list = ChildNodeList::create(node); 57 RefPtr<ChildNodeList> list = ChildNodeList::create(node);
58 m_childNodeList = list.get(); 58 m_childNodeList = list.get();
59 return list.release(); 59 return list.release();
60 } 60 }
61 61
62 PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node* node) 62 PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node)
63 { 63 {
64 if (m_childNodeList) 64 if (m_childNodeList)
65 return toEmptyNodeList(m_childNodeList); 65 return toEmptyNodeList(m_childNodeList);
66 RefPtr<EmptyNodeList> list = EmptyNodeList::create(node); 66 RefPtr<EmptyNodeList> list = EmptyNodeList::create(node);
67 m_childNodeList = list.get(); 67 m_childNodeList = list.get();
68 return list.release(); 68 return list.release();
69 } 69 }
70 70
71 void removeChildNodeList(ChildNodeList* list) 71 void removeChildNodeList(ChildNodeList* list)
72 { 72 {
(...skipping 17 matching lines...) Expand all
90 return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.fi rst; 90 return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.fi rst;
91 } 91 }
92 static bool equal(const std::pair<unsigned char, StringImpl*>& a, const std::pair<unsigned char, StringImpl*>& b) { return a == b; } 92 static bool equal(const std::pair<unsigned char, StringImpl*>& a, const std::pair<unsigned char, StringImpl*>& b) { return a == b; }
93 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl *>::Hash::safeToCompareToEmptyOrDeleted; 93 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl *>::Hash::safeToCompareToEmptyOrDeleted;
94 }; 94 };
95 95
96 typedef HashMap<std::pair<unsigned char, StringImpl*>, LiveNodeListBase*, No deListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap; 96 typedef HashMap<std::pair<unsigned char, StringImpl*>, LiveNodeListBase*, No deListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap;
97 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS; 97 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS;
98 98
99 template<typename T> 99 template<typename T>
100 PassRefPtr<T> addCache(ContainerNode* node, CollectionType collectionType, c onst AtomicString& name) 100 PassRefPtr<T> addCache(ContainerNode& node, CollectionType collectionType, c onst AtomicString& name)
101 { 101 {
102 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0); 102 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0);
103 if (!result.isNewEntry) 103 if (!result.isNewEntry)
104 return static_cast<T*>(result.storedValue->value); 104 return static_cast<T*>(result.storedValue->value);
105 105
106 RefPtr<T> list = T::create(node, collectionType, name); 106 RefPtr<T> list = T::create(node, collectionType, name);
107 result.storedValue->value = list.get(); 107 result.storedValue->value = list.get();
108 return list.release(); 108 return list.release();
109 } 109 }
110 110
111 template<typename T> 111 template<typename T>
112 PassRefPtr<T> addCache(ContainerNode* node, CollectionType collectionType) 112 PassRefPtr<T> addCache(ContainerNode& node, CollectionType collectionType)
113 { 113 {
114 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0); 114 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0);
115 if (!result.isNewEntry) 115 if (!result.isNewEntry)
116 return static_cast<T*>(result.storedValue->value); 116 return static_cast<T*>(result.storedValue->value);
117 117
118 RefPtr<T> list = T::create(node, collectionType); 118 RefPtr<T> list = T::create(node, collectionType);
119 result.storedValue->value = list.get(); 119 result.storedValue->value = list.get();
120 return list.release(); 120 return list.release();
121 } 121 }
122 122
123 template<typename T> 123 template<typename T>
124 T* cached(CollectionType collectionType) 124 T* cached(CollectionType collectionType)
125 { 125 {
126 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom))); 126 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom)));
127 } 127 }
128 128
129 PassRefPtr<TagCollection> addCache(ContainerNode* node, const AtomicString& namespaceURI, const AtomicString& localName) 129 PassRefPtr<TagCollection> addCache(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName)
130 { 130 {
131 QualifiedName name(nullAtom, localName, namespaceURI); 131 QualifiedName name(nullAtom, localName, namespaceURI);
132 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name , 0); 132 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name , 0);
133 if (!result.isNewEntry) 133 if (!result.isNewEntry)
134 return result.storedValue->value; 134 return result.storedValue->value;
135 135
136 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l ocalName); 136 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l ocalName);
137 result.storedValue->value = list.get(); 137 result.storedValue->value = list.get();
138 return list.release(); 138 return list.release();
139 } 139 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 ownerNode.clearNodeLists(); 276 ownerNode.clearNodeLists();
277 return true; 277 return true;
278 } 278 }
279 279
280 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow 280 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow
281 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); 281 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count);
282 282
283 } // namespace WebCore 283 } // namespace WebCore
284 284
285 #endif // NodeRareData_h 285 #endif // NodeRareData_h
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/TagCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698