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, |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 class LabelsNodeList; | 39 class LabelsNodeList; |
40 class RadioNodeList; | 40 class RadioNodeList; |
41 class TreeScope; | 41 class TreeScope; |
42 | 42 |
43 class NodeListsNodeData { | 43 class NodeListsNodeData { |
44 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; | 44 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; |
45 public: | 45 public: |
46 void clearChildNodeListCache() | 46 void clearChildNodeListCache() |
47 { | 47 { |
48 if (m_childNodeList) | 48 if (m_childNodeList && m_childNodeList->isLiveNodeList()) |
49 m_childNodeList->invalidateCache(); | 49 static_cast<LiveNodeList*>(m_childNodeList)->invalidateCache(); |
50 } | 50 } |
51 | 51 |
52 PassRefPtr<ChildNodeList> ensureChildNodeList(Node* node) | 52 PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode* node) |
53 { | 53 { |
54 if (m_childNodeList) | 54 if (m_childNodeList) { |
55 return m_childNodeList; | 55 ASSERT_WITH_SECURITY_IMPLICATION(!m_childNodeList->isEmptyNodeList() ); |
56 return static_cast<ChildNodeList*>(m_childNodeList); | |
57 } | |
56 RefPtr<ChildNodeList> list = ChildNodeList::create(node); | 58 RefPtr<ChildNodeList> list = ChildNodeList::create(node); |
57 m_childNodeList = list.get(); | 59 m_childNodeList = list.get(); |
58 return list.release(); | 60 return list.release(); |
59 } | 61 } |
60 | 62 |
63 PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node* node) | |
64 { | |
65 if (m_childNodeList) { | |
66 ASSERT_WITH_SECURITY_IMPLICATION(m_childNodeList->isEmptyNodeList()) ; | |
67 return static_cast<EmptyNodeList*>(m_childNodeList); | |
esprehn
2014/01/17 07:06:20
Add a casting method, there's macros for that. toE
Inactive
2014/01/17 15:00:48
Done.
| |
68 } | |
69 RefPtr<EmptyNodeList> list = EmptyNodeList::create(node); | |
esprehn
2014/01/17 07:06:20
If you reverse the clauses you can make this funct
Inactive
2014/01/17 15:00:48
The issue is that m_childNodeList is a raw pointer
| |
70 m_childNodeList = list.get(); | |
71 return list.release(); | |
72 } | |
73 | |
61 void removeChildNodeList(ChildNodeList* list) | 74 void removeChildNodeList(ChildNodeList* list) |
62 { | 75 { |
63 ASSERT(m_childNodeList == list); | 76 ASSERT(m_childNodeList == list); |
64 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de())) | 77 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de())) |
65 return; | 78 return; |
66 m_childNodeList = 0; | 79 m_childNodeList = 0; |
67 } | 80 } |
68 | 81 |
82 void removeEmptyChildNodeList(EmptyNodeList* list) | |
83 { | |
84 ASSERT(m_childNodeList == list); | |
85 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo de())) | |
86 return; | |
87 m_childNodeList = 0; | |
88 } | |
89 | |
69 template <typename StringType> | 90 template <typename StringType> |
70 struct NodeListCacheMapEntryHash { | 91 struct NodeListCacheMapEntryHash { |
71 static unsigned hash(const std::pair<unsigned char, StringType>& entry) | 92 static unsigned hash(const std::pair<unsigned char, StringType>& entry) |
72 { | 93 { |
73 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir st; | 94 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir st; |
74 } | 95 } |
75 static bool equal(const std::pair<unsigned char, StringType>& a, const s td::pair<unsigned char, StringType>& b) { return a == b; } | 96 static bool equal(const std::pair<unsigned char, StringType>& a, const s td::pair<unsigned char, StringType>& b) { return a == b; } |
76 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType >::Hash::safeToCompareToEmptyOrDeleted; | 97 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType >::Hash::safeToCompareToEmptyOrDeleted; |
77 }; | 98 }; |
78 | 99 |
79 typedef HashMap<std::pair<unsigned char, AtomicString>, LiveNodeListBase*, N odeListCacheMapEntryHash<AtomicString> > NodeListAtomicNameCacheMap; | 100 typedef HashMap<std::pair<unsigned char, AtomicString>, LiveNodeListBase*, N odeListCacheMapEntryHash<AtomicString> > NodeListAtomicNameCacheMap; |
80 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis tCacheMapEntryHash<String> > NodeListNameCacheMap; | 101 typedef HashMap<std::pair<unsigned char, String>, LiveNodeListBase*, NodeLis tCacheMapEntryHash<String> > NodeListNameCacheMap; |
81 typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS; | 102 typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS; |
82 | 103 |
83 template<typename T> | 104 template<typename T> |
84 PassRefPtr<T> addCacheWithAtomicName(Node* node, CollectionType collectionTy pe, const AtomicString& name) | 105 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType, const AtomicString& name) |
85 { | 106 { |
86 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0); | 107 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, name), 0); |
87 if (!result.isNewEntry) | 108 if (!result.isNewEntry) |
88 return static_cast<T*>(result.iterator->value); | 109 return static_cast<T*>(result.iterator->value); |
89 | 110 |
90 RefPtr<T> list = T::create(node, collectionType, name); | 111 RefPtr<T> list = T::create(node, collectionType, name); |
91 result.iterator->value = list.get(); | 112 result.iterator->value = list.get(); |
92 return list.release(); | 113 return list.release(); |
93 } | 114 } |
94 | 115 |
95 // FIXME: This function should be renamed since it doesn't have an atomic na me. | 116 // FIXME: This function should be renamed since it doesn't have an atomic na me. |
96 template<typename T> | 117 template<typename T> |
97 PassRefPtr<T> addCacheWithAtomicName(Node* node, CollectionType collectionTy pe) | 118 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col lectionType) |
98 { | 119 { |
99 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0); | 120 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na medNodeListKey(collectionType, starAtom), 0); |
100 if (!result.isNewEntry) | 121 if (!result.isNewEntry) |
101 return static_cast<T*>(result.iterator->value); | 122 return static_cast<T*>(result.iterator->value); |
102 | 123 |
103 RefPtr<T> list = T::create(node, collectionType); | 124 RefPtr<T> list = T::create(node, collectionType); |
104 result.iterator->value = list.get(); | 125 result.iterator->value = list.get(); |
105 return list.release(); | 126 return list.release(); |
106 } | 127 } |
107 | 128 |
108 template<typename T> | 129 template<typename T> |
109 T* cacheWithAtomicName(CollectionType collectionType) | 130 T* cacheWithAtomicName(CollectionType collectionType) |
110 { | 131 { |
111 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom))); | 132 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio nType, starAtom))); |
112 } | 133 } |
113 | 134 |
114 template<typename T> | 135 template<typename T> |
115 PassRefPtr<T> addCacheWithName(Node* node, CollectionType collectionType, co nst String& name) | 136 PassRefPtr<T> addCacheWithName(Node* node, CollectionType collectionType, co nst String& name) |
116 { | 137 { |
117 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK ey(collectionType, name), 0); | 138 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK ey(collectionType, name), 0); |
118 if (!result.isNewEntry) | 139 if (!result.isNewEntry) |
119 return static_cast<T*>(result.iterator->value); | 140 return static_cast<T*>(result.iterator->value); |
120 | 141 |
121 RefPtr<T> list = T::create(node, name); | 142 RefPtr<T> list = T::create(node, name); |
122 result.iterator->value = list.get(); | 143 result.iterator->value = list.get(); |
123 return list.release(); | 144 return list.release(); |
124 } | 145 } |
125 | 146 |
126 PassRefPtr<TagNodeList> addCacheWithQualifiedName(Node* node, const AtomicSt ring& namespaceURI, const AtomicString& localName) | 147 PassRefPtr<TagNodeList> addCacheWithQualifiedName(ContainerNode* node, const AtomicString& namespaceURI, const AtomicString& localName) |
127 { | 148 { |
128 QualifiedName name(nullAtom, localName, namespaceURI); | 149 QualifiedName name(nullAtom, localName, namespaceURI); |
129 TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0) ; | 150 TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0) ; |
130 if (!result.isNewEntry) | 151 if (!result.isNewEntry) |
131 return result.iterator->value; | 152 return result.iterator->value; |
132 | 153 |
133 RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, local Name); | 154 RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, local Name); |
134 result.iterator->value = list.get(); | 155 result.iterator->value = list.get(); |
135 return list.release(); | 156 return list.release(); |
136 } | 157 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 return std::pair<unsigned char, AtomicString>(type, name); | 236 return std::pair<unsigned char, AtomicString>(type, name); |
216 } | 237 } |
217 | 238 |
218 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name) | 239 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const String& name) |
219 { | 240 { |
220 return std::pair<unsigned char, String>(type, name); | 241 return std::pair<unsigned char, String>(type, name); |
221 } | 242 } |
222 | 243 |
223 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); | 244 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); |
224 | 245 |
225 // FIXME: m_childNodeList should be merged into m_atomicNameCaches or at lea st be shared with HTMLCollection returned by Element::children | 246 // Can be a ChildNodeList or an EmptyNodeList. |
226 // but it's tricky because invalidateCaches shouldn't invalidate this cache and adoptTreeScope shouldn't call registerNodeList or unregisterNodeList. | 247 NodeList* m_childNodeList; |
227 ChildNodeList* m_childNodeList; | |
228 NodeListAtomicNameCacheMap m_atomicNameCaches; | 248 NodeListAtomicNameCacheMap m_atomicNameCaches; |
229 NodeListNameCacheMap m_nameCaches; | 249 NodeListNameCacheMap m_nameCaches; |
230 TagNodeListCacheNS m_tagNodeListCacheNS; | 250 TagNodeListCacheNS m_tagNodeListCacheNS; |
231 }; | 251 }; |
232 | 252 |
233 class NodeMutationObserverData { | 253 class NodeMutationObserverData { |
234 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; | 254 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; |
235 public: | 255 public: |
236 Vector<OwnPtr<MutationObserverRegistration> > registry; | 256 Vector<OwnPtr<MutationObserverRegistration> > registry; |
237 HashSet<MutationObserverRegistration*> transientRegistry; | 257 HashSet<MutationObserverRegistration*> transientRegistry; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 ownerNode->clearNodeLists(); | 318 ownerNode->clearNodeLists(); |
299 return true; | 319 return true; |
300 } | 320 } |
301 | 321 |
302 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow | 322 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow |
303 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); | 323 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da ta_count); |
304 | 324 |
305 } // namespace WebCore | 325 } // namespace WebCore |
306 | 326 |
307 #endif // NodeRareData_h | 327 #endif // NodeRareData_h |
OLD | NEW |