| 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/LiveNodeList.h" | 27 #include "core/dom/LiveNodeList.h" |
| 27 #include "core/dom/MutationObserverRegistration.h" | 28 #include "core/dom/MutationObserverRegistration.h" |
| 28 #include "core/dom/QualifiedName.h" | 29 #include "core/dom/QualifiedName.h" |
| 29 #include "core/dom/TagNodeList.h" | 30 #include "core/dom/TagNodeList.h" |
| 30 #include "core/page/Page.h" | 31 #include "core/page/Page.h" |
| 31 #include "wtf/HashSet.h" | 32 #include "wtf/HashSet.h" |
| 32 #include "wtf/OwnPtr.h" | 33 #include "wtf/OwnPtr.h" |
| 33 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
| 34 #include "wtf/text/AtomicString.h" | 35 #include "wtf/text/AtomicString.h" |
| 35 #include "wtf/text/StringHash.h" | 36 #include "wtf/text/StringHash.h" |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 class LabelsNodeList; | 40 class LabelsNodeList; |
| 40 class RadioNodeList; | 41 class RadioNodeList; |
| 41 class TreeScope; | 42 class TreeScope; |
| 42 | 43 |
| 43 class NodeListsNodeData { | 44 class NodeListsNodeData { |
| 44 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; | 45 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; |
| 45 public: | 46 public: |
| 46 void clearChildNodeListCache() | 47 void clearChildNodeListCache() |
| 47 { | 48 { |
| 48 if (m_childNodeList) | 49 if (m_childNodeList && m_childNodeList->isChildNodeList()) |
| 49 m_childNodeList->invalidateCache(); | 50 toChildNodeList(m_childNodeList)->invalidateCache(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 PassRefPtr<ChildNodeList> ensureChildNodeList(Node* node) | 53 PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode* node) |
| 53 { | 54 { |
| 54 if (m_childNodeList) | 55 if (m_childNodeList) |
| 55 return m_childNodeList; | 56 return toChildNodeList(m_childNodeList); |
| 56 RefPtr<ChildNodeList> list = ChildNodeList::create(node); | 57 RefPtr<ChildNodeList> list = ChildNodeList::create(node); |
| 57 m_childNodeList = list.get(); | 58 m_childNodeList = list.get(); |
| 58 return list.release(); | 59 return list.release(); |
| 59 } | 60 } |
| 60 | 61 |
| 62 PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node* node) |
| 63 { |
| 64 if (m_childNodeList) |
| 65 return toEmptyNodeList(m_childNodeList); |
| 66 RefPtr<EmptyNodeList> list = EmptyNodeList::create(node); |
| 67 m_childNodeList = list.get(); |
| 68 return list.release(); |
| 69 } |
| 70 |
| 61 void removeChildNodeList(ChildNodeList* list) | 71 void removeChildNodeList(ChildNodeList* list) |
| 62 { | 72 { |
| 63 ASSERT(m_childNodeList == list); | 73 ASSERT(m_childNodeList == list); |
| 64 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 74 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 65 return; | 75 return; |
| 66 m_childNodeList = 0; | 76 m_childNodeList = 0; |
| 67 } | 77 } |
| 68 | 78 |
| 79 void removeEmptyChildNodeList(EmptyNodeList* list) |
| 80 { |
| 81 ASSERT(m_childNodeList == list); |
| 82 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 83 return; |
| 84 m_childNodeList = 0; |
| 85 } |
| 86 |
| 69 template <typename StringType> | 87 template <typename StringType> |
| 70 struct NodeListCacheMapEntryHash { | 88 struct NodeListCacheMapEntryHash { |
| 71 static unsigned hash(const std::pair<unsigned char, StringType>& entry) | 89 static unsigned hash(const std::pair<unsigned char, StringType>& entry) |
| 72 { | 90 { |
| 73 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir
st; | 91 return DefaultHash<StringType>::Hash::hash(entry.second) + entry.fir
st; |
| 74 } | 92 } |
| 75 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; } |
| 76 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType
>::Hash::safeToCompareToEmptyOrDeleted; | 94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringType
>::Hash::safeToCompareToEmptyOrDeleted; |
| 77 }; | 95 }; |
| 78 | 96 |
| 79 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; |
| 80 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; |
| 81 typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS; | 99 typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS; |
| 82 | 100 |
| 83 template<typename T> | 101 template<typename T> |
| 84 PassRefPtr<T> addCacheWithAtomicName(Node* node, CollectionType collectionTy
pe, const AtomicString& name) | 102 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col
lectionType, const AtomicString& name) |
| 85 { | 103 { |
| 86 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), 0); | 104 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), 0); |
| 87 if (!result.isNewEntry) | 105 if (!result.isNewEntry) |
| 88 return static_cast<T*>(result.iterator->value); | 106 return static_cast<T*>(result.iterator->value); |
| 89 | 107 |
| 90 RefPtr<T> list = T::create(node, collectionType, name); | 108 RefPtr<T> list = T::create(node, collectionType, name); |
| 91 result.iterator->value = list.get(); | 109 result.iterator->value = list.get(); |
| 92 return list.release(); | 110 return list.release(); |
| 93 } | 111 } |
| 94 | 112 |
| 95 // FIXME: This function should be renamed since it doesn't have an atomic na
me. | 113 // FIXME: This function should be renamed since it doesn't have an atomic na
me. |
| 96 template<typename T> | 114 template<typename T> |
| 97 PassRefPtr<T> addCacheWithAtomicName(Node* node, CollectionType collectionTy
pe) | 115 PassRefPtr<T> addCacheWithAtomicName(ContainerNode* node, CollectionType col
lectionType) |
| 98 { | 116 { |
| 99 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, starAtom), 0); | 117 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, starAtom), 0); |
| 100 if (!result.isNewEntry) | 118 if (!result.isNewEntry) |
| 101 return static_cast<T*>(result.iterator->value); | 119 return static_cast<T*>(result.iterator->value); |
| 102 | 120 |
| 103 RefPtr<T> list = T::create(node, collectionType); | 121 RefPtr<T> list = T::create(node, collectionType); |
| 104 result.iterator->value = list.get(); | 122 result.iterator->value = list.get(); |
| 105 return list.release(); | 123 return list.release(); |
| 106 } | 124 } |
| 107 | 125 |
| 108 template<typename T> | 126 template<typename T> |
| 109 T* cacheWithAtomicName(CollectionType collectionType) | 127 T* cacheWithAtomicName(CollectionType collectionType) |
| 110 { | 128 { |
| 111 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio
nType, starAtom))); | 129 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio
nType, starAtom))); |
| 112 } | 130 } |
| 113 | 131 |
| 114 template<typename T> | 132 template<typename T> |
| 115 PassRefPtr<T> addCacheWithName(Node* node, CollectionType collectionType, co
nst String& name) | 133 PassRefPtr<T> addCacheWithName(Node* node, CollectionType collectionType, co
nst String& name) |
| 116 { | 134 { |
| 117 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK
ey(collectionType, name), 0); | 135 NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListK
ey(collectionType, name), 0); |
| 118 if (!result.isNewEntry) | 136 if (!result.isNewEntry) |
| 119 return static_cast<T*>(result.iterator->value); | 137 return static_cast<T*>(result.iterator->value); |
| 120 | 138 |
| 121 RefPtr<T> list = T::create(node, name); | 139 RefPtr<T> list = T::create(node, name); |
| 122 result.iterator->value = list.get(); | 140 result.iterator->value = list.get(); |
| 123 return list.release(); | 141 return list.release(); |
| 124 } | 142 } |
| 125 | 143 |
| 126 PassRefPtr<TagNodeList> addCacheWithQualifiedName(Node* node, const AtomicSt
ring& namespaceURI, const AtomicString& localName) | 144 PassRefPtr<TagNodeList> addCacheWithQualifiedName(ContainerNode* node, const
AtomicString& namespaceURI, const AtomicString& localName) |
| 127 { | 145 { |
| 128 QualifiedName name(nullAtom, localName, namespaceURI); | 146 QualifiedName name(nullAtom, localName, namespaceURI); |
| 129 TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0)
; | 147 TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0)
; |
| 130 if (!result.isNewEntry) | 148 if (!result.isNewEntry) |
| 131 return result.iterator->value; | 149 return result.iterator->value; |
| 132 | 150 |
| 133 RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, local
Name); | 151 RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, local
Name); |
| 134 result.iterator->value = list.get(); | 152 result.iterator->value = list.get(); |
| 135 return list.release(); | 153 return list.release(); |
| 136 } | 154 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return std::pair<unsigned char, AtomicString>(type, name); | 233 return std::pair<unsigned char, AtomicString>(type, name); |
| 216 } | 234 } |
| 217 | 235 |
| 218 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const
String& name) | 236 std::pair<unsigned char, String> namedNodeListKey(CollectionType type, const
String& name) |
| 219 { | 237 { |
| 220 return std::pair<unsigned char, String>(type, name); | 238 return std::pair<unsigned char, String>(type, name); |
| 221 } | 239 } |
| 222 | 240 |
| 223 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); | 241 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node*); |
| 224 | 242 |
| 225 // FIXME: m_childNodeList should be merged into m_atomicNameCaches or at lea
st be shared with HTMLCollection returned by Element::children | 243 // 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. | 244 NodeList* m_childNodeList; |
| 227 ChildNodeList* m_childNodeList; | |
| 228 NodeListAtomicNameCacheMap m_atomicNameCaches; | 245 NodeListAtomicNameCacheMap m_atomicNameCaches; |
| 229 NodeListNameCacheMap m_nameCaches; | 246 NodeListNameCacheMap m_nameCaches; |
| 230 TagNodeListCacheNS m_tagNodeListCacheNS; | 247 TagNodeListCacheNS m_tagNodeListCacheNS; |
| 231 }; | 248 }; |
| 232 | 249 |
| 233 class NodeMutationObserverData { | 250 class NodeMutationObserverData { |
| 234 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; | 251 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); WTF_MAKE_FAST_ALLOCATED; |
| 235 public: | 252 public: |
| 236 Vector<OwnPtr<MutationObserverRegistration> > registry; | 253 Vector<OwnPtr<MutationObserverRegistration> > registry; |
| 237 HashSet<MutationObserverRegistration*> transientRegistry; | 254 HashSet<MutationObserverRegistration*> transientRegistry; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 ownerNode->clearNodeLists(); | 315 ownerNode->clearNodeLists(); |
| 299 return true; | 316 return true; |
| 300 } | 317 } |
| 301 | 318 |
| 302 // Ensure the 10 bits reserved for the m_connectedFrameCount cannot overflow | 319 // 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); | 320 COMPILE_ASSERT(Page::maxNumberOfFrames < 1024, Frame_limit_should_fit_in_rare_da
ta_count); |
| 304 | 321 |
| 305 } // namespace WebCore | 322 } // namespace WebCore |
| 306 | 323 |
| 307 #endif // NodeRareData_h | 324 #endif // NodeRareData_h |
| OLD | NEW |