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

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

Issue 138343007: Use more consistent naming for caching methods in NodeListsNodeData class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 10 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
« no previous file with comments | « Source/core/dom/NameNodeList.cpp ('k') | Source/core/dom/TagCollection.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 /* 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType, const 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.iterator->value); 104 return static_cast<T*>(result.iterator->value);
105 105
106 RefPtr<T> list = T::create(node, collectionType, name); 106 RefPtr<T> list = T::create(node, collectionType, name);
107 result.iterator->value = list.get(); 107 result.iterator->value = list.get();
108 return list.release(); 108 return list.release();
109 } 109 }
110 110
111 // FIXME: This function should be renamed since it doesn't have an atomic na me.
112 template<typename T> 111 template<typename T>
113 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType) 112 PassRefPtr<T> addCache(ContainerNode* node, CollectionType collectionType)
114 { 113 {
115 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0); 114 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0);
116 if (!result.isNewEntry) 115 if (!result.isNewEntry)
117 return static_cast<T*>(result.iterator->value); 116 return static_cast<T*>(result.iterator->value);
118 117
119 RefPtr<T> list = T::create(node, collectionType); 118 RefPtr<T> list = T::create(node, collectionType);
120 result.iterator->value = list.get(); 119 result.iterator->value = list.get();
121 return list.release(); 120 return list.release();
122 } 121 }
123 122
124 template<typename T> 123 template<typename T>
125 T* cacheWithAtomicName(CollectionType collectionType) 124 T* cached(CollectionType collectionType)
126 { 125 {
127 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom))); 126 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom)));
128 } 127 }
129 128
130 PassRefPtr<TagCollection> addCacheWithQualifiedName(ContainerNode* node, con st AtomicString& namespaceURI, const AtomicString& localName) 129 PassRefPtr<TagCollection> addCache(ContainerNode* node, const AtomicString& namespaceURI, const AtomicString& localName)
131 { 130 {
132 QualifiedName name(nullAtom, localName, namespaceURI); 131 QualifiedName name(nullAtom, localName, namespaceURI);
133 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name , 0); 132 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name , 0);
134 if (!result.isNewEntry) 133 if (!result.isNewEntry)
135 return result.iterator->value; 134 return result.iterator->value;
136 135
137 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l ocalName); 136 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l ocalName);
138 result.iterator->value = list.get(); 137 result.iterator->value = list.get();
139 return list.release(); 138 return list.release();
140 } 139 }
141 140
142 void removeCacheWithAtomicName(LiveNodeListBase* list, CollectionType collec tionType, const AtomicString& name = starAtom) 141 void removeCache(LiveNodeListBase* list, CollectionType collectionType, cons t AtomicString& name = starAtom)
143 { 142 {
144 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n ame))); 143 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n ame)));
145 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de())) 144 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de()))
146 return; 145 return;
147 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); 146 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name));
148 } 147 }
149 148
150 void removeCacheWithQualifiedName(LiveNodeListBase* list, const AtomicString & namespaceURI, const AtomicString& localName) 149 void removeCache(LiveNodeListBase* list, const AtomicString& namespaceURI, c onst AtomicString& localName)
151 { 150 {
152 QualifiedName name(nullAtom, localName, namespaceURI); 151 QualifiedName name(nullAtom, localName, namespaceURI);
153 ASSERT(list == m_tagCollectionCacheNS.get(name)); 152 ASSERT(list == m_tagCollectionCacheNS.get(name));
154 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de())) 153 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de()))
155 return; 154 return;
156 m_tagCollectionCacheNS.remove(name); 155 m_tagCollectionCacheNS.remove(name);
157 } 156 }
158 157
159 static PassOwnPtr<NodeListsNodeData> create() 158 static PassOwnPtr<NodeListsNodeData> create()
160 { 159 {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 ownerNode->clearNodeLists(); 281 ownerNode->clearNodeLists();
283 return true; 282 return true;
284 } 283 }
285 284
286 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow 285 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow
287 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); 286 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count);
288 287
289 } // namespace WebCore 288 } // namespace WebCore
290 289
291 #endif // NodeRareData_h 290 #endif // NodeRareData_h
OLDNEW
« no previous file with comments | « Source/core/dom/NameNodeList.cpp ('k') | Source/core/dom/TagCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698