| 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 24 matching lines...) Expand all Loading... |
| 35 #include "wtf/PassOwnPtr.h" | 35 #include "wtf/PassOwnPtr.h" |
| 36 #include "wtf/text/AtomicString.h" | 36 #include "wtf/text/AtomicString.h" |
| 37 #include "wtf/text/StringHash.h" | 37 #include "wtf/text/StringHash.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 class LabelsNodeList; | 41 class LabelsNodeList; |
| 42 class RadioNodeList; | 42 class RadioNodeList; |
| 43 class TreeScope; | 43 class TreeScope; |
| 44 | 44 |
| 45 class NodeListsNodeData { | 45 class NodeListsNodeData FINAL : public NoBaseWillBeGarbageCollectedFinalized<Nod
eListsNodeData> { |
| 46 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED; | 46 WTF_MAKE_NONCOPYABLE(NodeListsNodeData); |
| 47 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 47 public: | 48 public: |
| 48 void clearChildNodeListCache() | 49 void clearChildNodeListCache() |
| 49 { | 50 { |
| 50 if (m_childNodeList && m_childNodeList->isChildNodeList()) | 51 if (m_childNodeList && m_childNodeList->isChildNodeList()) |
| 51 toChildNodeList(m_childNodeList)->invalidateCache(); | 52 toChildNodeList(m_childNodeList)->invalidateCache(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 PassRefPtr<ChildNodeList> ensureChildNodeList(ContainerNode& node) | 55 PassRefPtrWillBeRawPtr<ChildNodeList> ensureChildNodeList(ContainerNode& nod
e) |
| 55 { | 56 { |
| 56 if (m_childNodeList) | 57 if (m_childNodeList) |
| 57 return toChildNodeList(m_childNodeList); | 58 return toChildNodeList(m_childNodeList); |
| 58 RefPtr<ChildNodeList> list = ChildNodeList::create(node); | 59 RefPtrWillBeRawPtr<ChildNodeList> list = ChildNodeList::create(node); |
| 59 m_childNodeList = list.get(); | 60 m_childNodeList = list.get(); |
| 60 return list.release(); | 61 return list.release(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 PassRefPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node) | 64 PassRefPtrWillBeRawPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node) |
| 64 { | 65 { |
| 65 if (m_childNodeList) | 66 if (m_childNodeList) |
| 66 return toEmptyNodeList(m_childNodeList); | 67 return toEmptyNodeList(m_childNodeList); |
| 67 RefPtr<EmptyNodeList> list = EmptyNodeList::create(node); | 68 RefPtrWillBeRawPtr<EmptyNodeList> list = EmptyNodeList::create(node); |
| 68 m_childNodeList = list.get(); | 69 m_childNodeList = list.get(); |
| 69 return list.release(); | 70 return list.release(); |
| 70 } | 71 } |
| 71 | 72 |
| 73 #if !ENABLE(OILPAN) |
| 72 void removeChildNodeList(ChildNodeList* list) | 74 void removeChildNodeList(ChildNodeList* list) |
| 73 { | 75 { |
| 74 ASSERT(m_childNodeList == list); | 76 ASSERT(m_childNodeList == list); |
| 75 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 77 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 76 return; | 78 return; |
| 77 m_childNodeList = 0; | 79 m_childNodeList = nullptr; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void removeEmptyChildNodeList(EmptyNodeList* list) | 82 void removeEmptyChildNodeList(EmptyNodeList* list) |
| 81 { | 83 { |
| 82 ASSERT(m_childNodeList == list); | 84 ASSERT(m_childNodeList == list); |
| 83 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 85 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 84 return; | 86 return; |
| 85 m_childNodeList = 0; | 87 m_childNodeList = nullptr; |
| 86 } | 88 } |
| 89 #endif |
| 87 | 90 |
| 88 struct NodeListAtomicCacheMapEntryHash { | 91 struct NodeListAtomicCacheMapEntryHash { |
| 89 static unsigned hash(const std::pair<unsigned char, StringImpl*>& entry) | 92 static unsigned hash(const std::pair<unsigned char, StringImpl*>& entry) |
| 90 { | 93 { |
| 91 return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.fi
rst; | 94 return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.fi
rst; |
| 92 } | 95 } |
| 93 static bool equal(const std::pair<unsigned char, StringImpl*>& a, const
std::pair<unsigned char, StringImpl*>& b) { return a == b; } | 96 static bool equal(const std::pair<unsigned char, StringImpl*>& a, const
std::pair<unsigned char, StringImpl*>& b) { return a == b; } |
| 94 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl
*>::Hash::safeToCompareToEmptyOrDeleted; | 97 static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl
*>::Hash::safeToCompareToEmptyOrDeleted; |
| 95 }; | 98 }; |
| 96 | 99 |
| 97 typedef HashMap<std::pair<unsigned char, StringImpl*>, LiveNodeListBase*, No
deListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap; | 100 // Oilpan: keep a weak reference to the collection objects. |
| 98 typedef HashMap<QualifiedName, TagCollection*> TagCollectionCacheNS; | 101 // Explicit object unregistration in a non-Oilpan setting |
| 102 // on object destruction is replaced by the garbage collector |
| 103 // clearing out their weak reference. |
| 104 typedef WillBeHeapHashMap<std::pair<unsigned char, StringImpl*>, RawPtrWillB
eWeakMember<LiveNodeListBase>, NodeListAtomicCacheMapEntryHash> NodeListAtomicNa
meCacheMap; |
| 105 typedef WillBeHeapHashMap<QualifiedName, RawPtrWillBeWeakMember<TagCollectio
n> > TagCollectionCacheNS; |
| 99 | 106 |
| 100 template<typename T> | 107 template<typename T> |
| 101 PassRefPtr<T> addCache(ContainerNode& node, CollectionType collectionType, c
onst AtomicString& name) | 108 PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType colle
ctionType, const AtomicString& name) |
| 102 { | 109 { |
| 103 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), 0); | 110 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, name), nullptr); |
| 104 if (!result.isNewEntry) | 111 if (!result.isNewEntry) |
| 105 return static_cast<T*>(result.storedValue->value); | 112 return static_cast<T*>(result.storedValue->value.get()); |
| 106 | 113 |
| 107 RefPtr<T> list = T::create(node, collectionType, name); | 114 RefPtrWillBeRawPtr<T> list = T::create(node, collectionType, name); |
| 108 result.storedValue->value = list.get(); | 115 result.storedValue->value = list.get(); |
| 109 return list.release(); | 116 return list.release(); |
| 110 } | 117 } |
| 111 | 118 |
| 112 template<typename T> | 119 template<typename T> |
| 113 PassRefPtr<T> addCache(ContainerNode& node, CollectionType collectionType) | 120 PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType colle
ctionType) |
| 114 { | 121 { |
| 115 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, starAtom), 0); | 122 NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(na
medNodeListKey(collectionType, starAtom), nullptr); |
| 116 if (!result.isNewEntry) | 123 if (!result.isNewEntry) |
| 117 return static_cast<T*>(result.storedValue->value); | 124 return static_cast<T*>(result.storedValue->value.get()); |
| 118 | 125 |
| 119 RefPtr<T> list = T::create(node, collectionType); | 126 RefPtrWillBeRawPtr<T> list = T::create(node, collectionType); |
| 120 result.storedValue->value = list.get(); | 127 result.storedValue->value = list.get(); |
| 121 return list.release(); | 128 return list.release(); |
| 122 } | 129 } |
| 123 | 130 |
| 124 template<typename T> | 131 template<typename T> |
| 125 T* cached(CollectionType collectionType) | 132 T* cached(CollectionType collectionType) |
| 126 { | 133 { |
| 134 #if ENABLE(OILPAN) |
| 135 // FIXME: Oilpan: unify, if possible. The lookup resolves to a T& with O
ilpan, |
| 136 // whereas non-Oilpan resolves to RawPtr<T>. |
| 127 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio
nType, starAtom))); | 137 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio
nType, starAtom))); |
| 138 #else |
| 139 return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectio
nType, starAtom)).get()); |
| 140 #endif |
| 128 } | 141 } |
| 129 | 142 |
| 130 PassRefPtr<TagCollection> addCache(ContainerNode& node, const AtomicString&
namespaceURI, const AtomicString& localName) | 143 PassRefPtrWillBeRawPtr<TagCollection> addCache(ContainerNode& node, const At
omicString& namespaceURI, const AtomicString& localName) |
| 131 { | 144 { |
| 132 QualifiedName name(nullAtom, localName, namespaceURI); | 145 QualifiedName name(nullAtom, localName, namespaceURI); |
| 133 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name
, 0); | 146 TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name
, nullptr); |
| 134 if (!result.isNewEntry) | 147 if (!result.isNewEntry) |
| 135 return result.storedValue->value; | 148 return result.storedValue->value; |
| 136 | 149 |
| 137 RefPtr<TagCollection> list = TagCollection::create(node, namespaceURI, l
ocalName); | 150 RefPtrWillBeRawPtr<TagCollection> list = TagCollection::create(node, nam
espaceURI, localName); |
| 138 result.storedValue->value = list.get(); | 151 result.storedValue->value = list.get(); |
| 139 return list.release(); | 152 return list.release(); |
| 140 } | 153 } |
| 141 | 154 |
| 155 #if !ENABLE(OILPAN) |
| 142 void removeCache(LiveNodeListBase* list, CollectionType collectionType, cons
t AtomicString& name = starAtom) | 156 void removeCache(LiveNodeListBase* list, CollectionType collectionType, cons
t AtomicString& name = starAtom) |
| 143 { | 157 { |
| 144 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n
ame))); | 158 ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, n
ame))); |
| 145 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 159 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 146 return; | 160 return; |
| 147 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); | 161 m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); |
| 148 } | 162 } |
| 149 | 163 |
| 150 void removeCache(LiveNodeListBase* list, const AtomicString& namespaceURI, c
onst AtomicString& localName) | 164 void removeCache(LiveNodeListBase* list, const AtomicString& namespaceURI, c
onst AtomicString& localName) |
| 151 { | 165 { |
| 152 QualifiedName name(nullAtom, localName, namespaceURI); | 166 QualifiedName name(nullAtom, localName, namespaceURI); |
| 153 ASSERT(list == m_tagCollectionCacheNS.get(name)); | 167 ASSERT(list == m_tagCollectionCacheNS.get(name)); |
| 154 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) | 168 if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNo
de())) |
| 155 return; | 169 return; |
| 156 m_tagCollectionCacheNS.remove(name); | 170 m_tagCollectionCacheNS.remove(name); |
| 157 } | 171 } |
| 172 #endif |
| 158 | 173 |
| 159 static PassOwnPtr<NodeListsNodeData> create() | 174 static PassOwnPtrWillBeRawPtr<NodeListsNodeData> create() |
| 160 { | 175 { |
| 161 return adoptPtr(new NodeListsNodeData); | 176 return adoptPtrWillBeNoop(new NodeListsNodeData); |
| 162 } | 177 } |
| 163 | 178 |
| 164 void invalidateCaches(const QualifiedName* attrName = 0); | 179 void invalidateCaches(const QualifiedName* attrName = 0); |
| 180 |
| 165 bool isEmpty() const | 181 bool isEmpty() const |
| 166 { | 182 { |
| 167 return m_atomicNameCaches.isEmpty() && m_tagCollectionCacheNS.isEmpty(); | 183 return !m_childNodeList && m_atomicNameCaches.isEmpty() && m_tagCollecti
onCacheNS.isEmpty(); |
| 168 } | 184 } |
| 169 | 185 |
| 170 void adoptTreeScope() | 186 void adoptTreeScope() |
| 171 { | 187 { |
| 172 invalidateCaches(); | 188 invalidateCaches(); |
| 173 } | 189 } |
| 174 | 190 |
| 175 void adoptDocument(Document& oldDocument, Document& newDocument) | 191 void adoptDocument(Document& oldDocument, Document& newDocument) |
| 176 { | 192 { |
| 177 ASSERT(oldDocument != newDocument); | 193 ASSERT(oldDocument != newDocument); |
| 178 | 194 |
| 179 NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_atomic
NameCaches.end(); | 195 NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_atomic
NameCaches.end(); |
| 180 for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCaches.
begin(); it != atomicNameCacheEnd; ++it) { | 196 for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCaches.
begin(); it != atomicNameCacheEnd; ++it) { |
| 181 LiveNodeListBase* list = it->value; | 197 LiveNodeListBase* list = it->value; |
| 182 list->didMoveToDocument(oldDocument, newDocument); | 198 list->didMoveToDocument(oldDocument, newDocument); |
| 183 } | 199 } |
| 184 | 200 |
| 185 TagCollectionCacheNS::const_iterator tagEnd = m_tagCollectionCacheNS.end
(); | 201 TagCollectionCacheNS::const_iterator tagEnd = m_tagCollectionCacheNS.end
(); |
| 186 for (TagCollectionCacheNS::const_iterator it = m_tagCollectionCacheNS.be
gin(); it != tagEnd; ++it) { | 202 for (TagCollectionCacheNS::const_iterator it = m_tagCollectionCacheNS.be
gin(); it != tagEnd; ++it) { |
| 187 LiveNodeListBase* list = it->value; | 203 LiveNodeListBase* list = it->value; |
| 188 ASSERT(!list->isRootedAtDocument()); | 204 ASSERT(!list->isRootedAtDocument()); |
| 189 list->didMoveToDocument(oldDocument, newDocument); | 205 list->didMoveToDocument(oldDocument, newDocument); |
| 190 } | 206 } |
| 191 } | 207 } |
| 192 | 208 |
| 209 void trace(Visitor*); |
| 210 |
| 193 private: | 211 private: |
| 194 NodeListsNodeData() | 212 NodeListsNodeData() |
| 195 : m_childNodeList(0) | 213 : m_childNodeList(nullptr) |
| 196 { } | 214 { } |
| 197 | 215 |
| 198 std::pair<unsigned char, StringImpl*> namedNodeListKey(CollectionType type,
const AtomicString& name) | 216 std::pair<unsigned char, StringImpl*> namedNodeListKey(CollectionType type,
const AtomicString& name) |
| 199 { | 217 { |
| 200 // Holding the raw StringImpl is safe because |name| is retained by the
NodeList and the NodeList | 218 // Holding the raw StringImpl is safe because |name| is retained by the
NodeList and the NodeList |
| 201 // is reponsible for removing itself from the cache on deletion. | 219 // is reponsible for removing itself from the cache on deletion. |
| 202 return std::pair<unsigned char, StringImpl*>(type, name.impl()); | 220 return std::pair<unsigned char, StringImpl*>(type, name.impl()); |
| 203 } | 221 } |
| 204 | 222 |
| 223 #if !ENABLE(OILPAN) |
| 205 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node&); | 224 bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node&); |
| 225 #endif |
| 206 | 226 |
| 207 // Can be a ChildNodeList or an EmptyNodeList. | 227 // Can be a ChildNodeList or an EmptyNodeList. |
| 208 NodeList* m_childNodeList; | 228 RawPtrWillBeWeakMember<NodeList> m_childNodeList; |
| 209 NodeListAtomicNameCacheMap m_atomicNameCaches; | 229 NodeListAtomicNameCacheMap m_atomicNameCaches; |
| 210 TagCollectionCacheNS m_tagCollectionCacheNS; | 230 TagCollectionCacheNS m_tagCollectionCacheNS; |
| 211 }; | 231 }; |
| 212 | 232 |
| 213 class NodeMutationObserverData FINAL : public NoBaseWillBeGarbageCollected<NodeM
utationObserverData> { | 233 class NodeMutationObserverData FINAL : public NoBaseWillBeGarbageCollected<NodeM
utationObserverData> { |
| 214 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); | 234 WTF_MAKE_NONCOPYABLE(NodeMutationObserverData); |
| 215 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | 235 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 216 public: | 236 public: |
| 217 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> > registry
; | 237 WillBeHeapVector<OwnPtrWillBeMember<MutationObserverRegistration> > registry
; |
| 218 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > transie
ntRegistry; | 238 WillBeHeapHashSet<RawPtrWillBeMember<MutationObserverRegistration> > transie
ntRegistry; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 enum { | 302 enum { |
| 283 ConnectedFrameCountBits = 10, // Must fit Page::maxNumberOfFrames. | 303 ConnectedFrameCountBits = 10, // Must fit Page::maxNumberOfFrames. |
| 284 }; | 304 }; |
| 285 | 305 |
| 286 void trace(Visitor*); | 306 void trace(Visitor*); |
| 287 | 307 |
| 288 void traceAfterDispatch(Visitor*); | 308 void traceAfterDispatch(Visitor*); |
| 289 void finalizeGarbageCollectedObject(); | 309 void finalizeGarbageCollectedObject(); |
| 290 | 310 |
| 291 protected: | 311 protected: |
| 292 NodeRareData(RenderObject* renderer) | 312 explicit NodeRareData(RenderObject* renderer) |
| 293 : NodeRareDataBase(renderer) | 313 : NodeRareDataBase(renderer) |
| 294 , m_connectedFrameCount(0) | 314 , m_connectedFrameCount(0) |
| 295 , m_elementFlags(0) | 315 , m_elementFlags(0) |
| 296 , m_restyleFlags(0) | 316 , m_restyleFlags(0) |
| 297 , m_isElementRareData(false) | 317 , m_isElementRareData(false) |
| 298 { } | 318 { } |
| 299 | 319 |
| 300 private: | 320 private: |
| 301 OwnPtr<NodeListsNodeData> m_nodeLists; | 321 OwnPtrWillBeMember<NodeListsNodeData> m_nodeLists; |
| 302 OwnPtrWillBeMember<NodeMutationObserverData> m_mutationObserverData; | 322 OwnPtrWillBeMember<NodeMutationObserverData> m_mutationObserverData; |
| 303 | 323 |
| 304 unsigned m_connectedFrameCount : ConnectedFrameCountBits; | 324 unsigned m_connectedFrameCount : ConnectedFrameCountBits; |
| 305 unsigned m_elementFlags : NumberOfElementFlags; | 325 unsigned m_elementFlags : NumberOfElementFlags; |
| 306 unsigned m_restyleFlags : NumberOfDynamicRestyleFlags; | 326 unsigned m_restyleFlags : NumberOfDynamicRestyleFlags; |
| 307 protected: | 327 protected: |
| 308 unsigned m_isElementRareData : 1; | 328 unsigned m_isElementRareData : 1; |
| 309 }; | 329 }; |
| 310 | 330 |
| 331 #if !ENABLE(OILPAN) |
| 311 inline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLas
tList(Node& ownerNode) | 332 inline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLas
tList(Node& ownerNode) |
| 312 { | 333 { |
| 313 ASSERT(ownerNode.nodeLists() == this); | 334 ASSERT(ownerNode.nodeLists() == this); |
| 314 if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_tagCollectionC
acheNS.size() != 1) | 335 if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_tagCollectionC
acheNS.size() != 1) |
| 315 return false; | 336 return false; |
| 316 ownerNode.clearNodeLists(); | 337 ownerNode.clearNodeLists(); |
| 317 return true; | 338 return true; |
| 318 } | 339 } |
| 340 #endif |
| 319 | 341 |
| 320 } // namespace WebCore | 342 } // namespace WebCore |
| 321 | 343 |
| 322 #endif // NodeRareData_h | 344 #endif // NodeRareData_h |
| OLD | NEW |