OLD | NEW |
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, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 * | 19 * |
20 */ | 20 */ |
21 | 21 |
22 #ifndef NodeRareData_h | 22 #ifndef NodeRareData_h |
23 #define NodeRareData_h | 23 #define NodeRareData_h |
24 | 24 |
25 #include "core/dom/ChildNodeList.h" | 25 #include "core/dom/ChildNodeList.h" |
26 #include "core/dom/EmptyNodeList.h" | 26 #include "core/dom/EmptyNodeList.h" |
27 #include "core/dom/LiveNodeList.h" | 27 #include "core/dom/LiveNodeList.h" |
28 #include "core/dom/MutationObserverRegistration.h" | 28 #include "core/dom/MutationObserverRegistration.h" |
29 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
30 #include "core/dom/TagNodeList.h" | 30 #include "core/dom/TagCollection.h" |
31 #include "core/page/Page.h" | 31 #include "core/page/Page.h" |
32 #include "wtf/HashSet.h" | 32 #include "wtf/HashSet.h" |
33 #include "wtf/OwnPtr.h" | 33 #include "wtf/OwnPtr.h" |
34 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
35 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
36 #include "wtf/text/StringHash.h" | 36 #include "wtf/text/StringHash.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 class LabelsNodeList; | 40 class LabelsNodeList; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 static unsigned hash(const std::pair<unsigned char, StringType>& entry) | 89 static unsigned hash(const std::pair<unsigned char, StringType>& entry) |
90 { | 90 { |
91 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir
st; | 91 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir
st; |
92 } | 92 } |
93 static bool equal(const std::pair<unsigned char, StringType>& a, const s
td::pair<unsigned char, StringType>& b) { return a == b; } | 93 static bool equal(const std::pair<unsigned char, StringType>& a, const s
td::pair<unsigned char, StringType>& b) { return a == b; } |
94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType
>::Hash::safeToCompareToEmptyOrDeleted; | 94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType
>::Hash::safeToCompareToEmptyOrDeleted; |
95 }; | 95 }; |
96 | 96 |
97 typedef HashMap<std::pair<unsigned char, AtomicString>, LiveNodeListBase*, N
odeListCacheMapEntryHash<AtomicString> > NodeListAtomicNameCacheMap; | 97 typedef HashMap<std::pair<unsigned char, AtomicString>, LiveNodeListBase*, N
odeListCacheMapEntryHash<AtomicString> > NodeListAtomicNameCacheMap; |
98 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis
tCacheMapEntryHash<String> > NodeListNameCacheMap; | 98 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis
tCacheMapEntryHash<String> > NodeListNameCacheMap; |
99 typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS; | 99 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS; |
100 | 100 |
101 template<typename T> | 101 template<typename T> |
102 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col
lectionType, const AtomicString& name) | 102 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col
lectionType, const AtomicString& name) |
103 { | 103 { |
104 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), 0); | 104 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), 0); |
105 if (!result.isNewEntry) | 105 if (!result.isNewEntry) |
106 return static_cast<T*>(result.iterator->value); | 106 return static_cast<T*>(result.iterator->value); |
107 | 107 |
108 RefPtr<T> list = T::create(node, collectionType, name); | 108 RefPtr<T> list = T::create(node, collectionType, name); |
109 result.iterator->value = list.get(); | 109 result.iterator->value = list.get(); |
(...skipping 24 matching lines...) Expand all Loading... |
134 { | 134 { |
135 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK
ey(collectionType, name), 0); | 135 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK
ey(collectionType, name), 0); |
136 if (!result.isNewEntry) | 136 if (!result.isNewEntry) |
137 return static_cast<T*>(result.iterator->value); | 137 return static_cast<T*>(result.iterator->value); |
138 | 138 |
139 RefPtr<T> list = T::create(node, name); | 139 RefPtr<T> list = T::create(node, name); |
140 result.iterator->value = list.get(); | 140 result.iterator->value = list.get(); |
141 return list.release(); | 141 return list.release(); |
142 } | 142 } |
143 | 143 |
144 PassRefPtr<TagNodeList> addCacheWithQualifiedName(ContainerNode* node, const
AtomicString& namespaceURI, const AtomicString& localName) | 144 PassRefPtr<TagCollection> addCacheWithQualifiedName(ContainerNode* node, con
st AtomicString& namespaceURI, const AtomicString& localName) |
145 { | 145 { |
146 QualifiedName name(nullAtom, localName, namespaceURI); | 146 QualifiedName name(nullAtom, localName, namespaceURI); |
147 TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0)
; | 147 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name
, 0); |
148 if (!result.isNewEntry) | 148 if (!result.isNewEntry) |
149 return result.iterator->value; | 149 return result.iterator->value; |
150 | 150 |
151 RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, local
Name); | 151 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l
ocalName); |
152 result.iterator->value = list.get(); | 152 result.iterator->value = list.get(); |
153 return list.release(); | 153 return list.release(); |
154 } | 154 } |
155 | 155 |
156 void removeCacheWithAtomicName(LiveNodeListBase* list, CollectionType collec
tionType, const AtomicString& name = starAtom) | 156 void removeCacheWithAtomicName(LiveNodeListBase* list, CollectionType collec
tionType, const AtomicString& name = starAtom) |
157 { | 157 { |
158 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n
ame))); | 158 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n
ame))); |
159 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 159 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
160 return; | 160 return; |
161 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); | 161 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); |
162 } | 162 } |
163 | 163 |
164 void removeCacheWithName(LiveNodeListBase* list, CollectionType collectionTy
pe, const String& name) | 164 void removeCacheWithName(LiveNodeListBase* list, CollectionType collectionTy
pe, const String& name) |
165 { | 165 { |
166 ASSERT(list == m_nameCaches.get(namedNodeListKey(collectionType, name)))
; | 166 ASSERT(list == m_nameCaches.get(namedNodeListKey(collectionType, name)))
; |
167 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 167 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
168 return; | 168 return; |
169 m_nameCaches.remove(namedNodeListKey(collectionType, name)); | 169 m_nameCaches.remove(namedNodeListKey(collectionType, name)); |
170 } | 170 } |
171 | 171 |
172 void removeCacheWithQualifiedName(LiveNodeList* list, const AtomicString& na
mespaceURI, const AtomicString& localName) | 172 void removeCacheWithQualifiedName(LiveNodeListBase* list, const AtomicString
& namespaceURI, const AtomicString& localName) |
173 { | 173 { |
174 QualifiedName name(nullAtom, localName, namespaceURI); | 174 QualifiedName name(nullAtom, localName, namespaceURI); |
175 ASSERT(list == m_tagNodeListCacheNS.get(name)); | 175 ASSERT(list == m_tagCollectionCacheNS.get(name)); |
176 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 176 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
177 return; | 177 return; |
178 m_tagNodeListCacheNS.remove(name); | 178 m_tagCollectionCacheNS.remove(name); |
179 } | 179 } |
180 | 180 |
181 static PassOwnPtr<NodeListsNodeData> create() | 181 static PassOwnPtr<NodeListsNodeData> create() |
182 { | 182 { |
183 return adoptPtr(new NodeListsNodeData); | 183 return adoptPtr(new NodeListsNodeData); |
184 } | 184 } |
185 | 185 |
186 void invalidateCaches(const QualifiedName* attrName = 0); | 186 void invalidateCaches(const QualifiedName* attrName = 0); |
187 bool isEmpty() const | 187 bool isEmpty() const |
188 { | 188 { |
189 return m_atomicNameCaches.isEmpty() && m_nameCaches.isEmpty() && m_tagNo
deListCacheNS.isEmpty(); | 189 return m_atomicNameCaches.isEmpty() && m_nameCaches.isEmpty() && m_tagCo
llectionCacheNS.isEmpty(); |
190 } | 190 } |
191 | 191 |
192 void adoptTreeScope() | 192 void adoptTreeScope() |
193 { | 193 { |
194 invalidateCaches(); | 194 invalidateCaches(); |
195 } | 195 } |
196 | 196 |
197 void adoptDocument(Document& oldDocument, Document& newDocument) | 197 void adoptDocument(Document& oldDocument, Document& newDocument) |
198 { | 198 { |
199 invalidateCaches(); | 199 invalidateCaches(); |
200 | 200 |
201 if (oldDocument != newDocument) { | 201 if (oldDocument != newDocument) { |
202 NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_at
omicNameCaches.end(); | 202 NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_at
omicNameCaches.end(); |
203 for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCac
hes.begin(); it != atomicNameCacheEnd; ++it) { | 203 for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCac
hes.begin(); it != atomicNameCacheEnd; ++it) { |
204 LiveNodeListBase* list = it->value; | 204 LiveNodeListBase* list = it->value; |
205 oldDocument.unregisterNodeList(list); | 205 oldDocument.unregisterNodeList(list); |
206 newDocument.registerNodeList(list); | 206 newDocument.registerNodeList(list); |
207 } | 207 } |
208 | 208 |
209 NodeListNameCacheMap::const_iterator nameCacheEnd = m_nameCaches.end
(); | 209 NodeListNameCacheMap::const_iterator nameCacheEnd = m_nameCaches.end
(); |
210 for (NodeListNameCacheMap::const_iterator it = m_nameCaches.begin();
it != nameCacheEnd; ++it) { | 210 for (NodeListNameCacheMap::const_iterator it = m_nameCaches.begin();
it != nameCacheEnd; ++it) { |
211 LiveNodeListBase* list = it->value; | 211 LiveNodeListBase* list = it->value; |
212 oldDocument.unregisterNodeList(list); | 212 oldDocument.unregisterNodeList(list); |
213 newDocument.registerNodeList(list); | 213 newDocument.registerNodeList(list); |
214 } | 214 } |
215 | 215 |
216 TagNodeListCacheNS::const_iterator tagEnd = m_tagNodeListCacheNS.end
(); | 216 TagCollectionCacheNS::const_iterator tagEnd = m_tagCollectionCacheNS
.end(); |
217 for (TagNodeListCacheNS::const_iterator it = m_tagNodeListCacheNS.be
gin(); it != tagEnd; ++it) { | 217 for (TagCollectionCacheNS::const_iterator it = m_tagCollectionCacheN
S.begin(); it != tagEnd; ++it) { |
218 LiveNodeListBase* list = it->value; | 218 LiveNodeListBase* list = it->value; |
219 ASSERT(!list->isRootedAtDocument()); | 219 ASSERT(!list->isRootedAtDocument()); |
220 oldDocument.unregisterNodeList(list); | 220 oldDocument.unregisterNodeList(list); |
221 newDocument.registerNodeList(list); | 221 newDocument.registerNodeList(list); |
222 } | 222 } |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 private: | 226 private: |
227 NodeListsNodeData() | 227 NodeListsNodeData() |
228 : m_childNodeList(0) | 228 : m_childNodeList(0) |
229 { } | 229 { } |
230 | 230 |
231 std::pair<unsigned char, AtomicString> namedNodeListKey(CollectionType type,
const AtomicString& name) | 231 std::pair<unsigned char, AtomicString> namedNodeListKey(CollectionType type,
const AtomicString& name) |
232 { | 232 { |
233 return std::pair<unsigned char, AtomicString>(type, name); | 233 return std::pair<unsigned char, AtomicString>(type, name); |
234 } | 234 } |
235 | 235 |
236 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const
String& name) | 236 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const
String& name) |
237 { | 237 { |
238 return std::pair<unsigned char, String>(type, name); | 238 return std::pair<unsigned char, String>(type, name); |
239 } | 239 } |
240 | 240 |
241 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); | 241 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); |
242 | 242 |
243 // Can be a ChildNodeList or an EmptyNodeList. | 243 // Can be a ChildNodeList or an EmptyNodeList. |
244 NodeList* m_childNodeList; | 244 NodeList* m_childNodeList; |
245 NodeListAtomicNameCacheMap m_atomicNameCaches; | 245 NodeListAtomicNameCacheMap m_atomicNameCaches; |
246 NodeListNameCacheMap m_nameCaches; | 246 NodeListNameCacheMap m_nameCaches; |
247 TagNodeListCacheNS m_tagNodeListCacheNS; | 247 TagCollectionCacheNS m_tagCollectionCacheNS; |
248 }; | 248 }; |
249 | 249 |
250 class NodeMutationObserverData { | 250 class NodeMutationObserverData { |
251 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; | 251 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; |
252 public: | 252 public: |
253 Vector<OwnPtr<MutationObserverRegistration> > registry; | 253 Vector<OwnPtr<MutationObserverRegistration> > registry; |
254 HashSet<MutationObserverRegistration*> transientRegistry; | 254 HashSet<MutationObserverRegistration*> transientRegistry; |
255 | 255 |
256 static PassOwnPtr<NodeMutationObserverData> create() { return adoptPtr(new N
odeMutationObserverData); } | 256 static PassOwnPtr<NodeMutationObserverData> create() { return adoptPtr(new N
odeMutationObserverData); } |
257 | 257 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 unsigned m_connectedFrameCount : 10; // Must fit Page::maxNumberOfFrames. | 303 unsigned m_connectedFrameCount : 10; // Must fit Page::maxNumberOfFrames. |
304 | 304 |
305 OwnPtr<NodeListsNodeData> m_nodeLists; | 305 OwnPtr<NodeListsNodeData> m_nodeLists; |
306 OwnPtr<NodeMutationObserverData> m_mutationObserverData; | 306 OwnPtr<NodeMutationObserverData> m_mutationObserverData; |
307 }; | 307 }; |
308 | 308 |
309 inline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLas
tList(Node* ownerNode) | 309 inline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLas
tList(Node* ownerNode) |
310 { | 310 { |
311 ASSERT(ownerNode); | 311 ASSERT(ownerNode); |
312 ASSERT(ownerNode->nodeLists() == this); | 312 ASSERT(ownerNode->nodeLists() == this); |
313 if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_nameCaches.siz
e() + m_tagNodeListCacheNS.size() != 1) | 313 if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_nameCaches.siz
e() + m_tagCollectionCacheNS.size() != 1) |
314 return false; | 314 return false; |
315 ownerNode->clearNodeLists(); | 315 ownerNode->clearNodeLists(); |
316 return true; | 316 return true; |
317 } | 317 } |
318 | 318 |
319 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow | 319 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow |
320 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da
ta_count); | 320 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da
ta_count); |
321 | 321 |
322 } // namespace WebCore | 322 } // namespace WebCore |
323 | 323 |
324 #endif // NodeRareData_h | 324 #endif // NodeRareData_h |
OLD | NEW |