1197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch/* 2197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. 3197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * Copyright (C) 2008 David Smith <catfish.man@gmail.com> 4197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * 5197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * This library is free software; you can redistribute it and/or 6197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * modify it under the terms of the GNU Library General Public 7197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * License as published by the Free Software Foundation; either 8197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * version 2 of the License, or (at your option) any later version. 9197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * 10197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * This library is distributed in the hope that it will be useful, 11197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * but WITHOUT ANY WARRANTY; without even the implied warranty of 12197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * Library General Public License for more details. 14197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * 15197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * You should have received a copy of the GNU Library General Public License 16197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * along with this library; see the file COPYING.LIB. If not, write to 17197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * Boston, MA 02110-1301, USA. 19197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch * 20197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch */ 21197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 22197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#ifndef NodeListsNodeData_h 23197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define NodeListsNodeData_h 24197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 25197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/ChildNodeList.h" 26197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/EmptyNodeList.h" 27197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/QualifiedName.h" 28197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/TagCollection.h" 29197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/html/CollectionType.h" 30197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/heap/Handle.h" 31197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "wtf/text/AtomicString.h" 32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "wtf/text/StringHash.h" 33197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 34c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 36197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass NodeListsNodeData FINAL : public NoBaseWillBeGarbageCollectedFinalized<NodeListsNodeData> { 37197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch WTF_MAKE_NONCOPYABLE(NodeListsNodeData); 38197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 39197021e6b966cfb06891637935ef33fff06433d1Ben Murdochpublic: 40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ChildNodeList* childNodeList(ContainerNode& node) 41197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 42c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_UNUSED(node, !m_childNodeList || node == m_childNodeList->virtualOwnerNode()); 43c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) return toChildNodeList(m_childNodeList); 44197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 46197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<ChildNodeList> ensureChildNodeList(ContainerNode& node) 47197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 48197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (m_childNodeList) 49197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return toChildNodeList(m_childNodeList); 50197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtrWillBeRawPtr<ChildNodeList> list = ChildNodeList::create(node); 51197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_childNodeList = list.get(); 52197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return list.release(); 53197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 54197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 55197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node) 56197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 57197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (m_childNodeList) 58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return toEmptyNodeList(m_childNodeList); 59197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtrWillBeRawPtr<EmptyNodeList> list = EmptyNodeList::create(node); 60197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_childNodeList = list.get(); 61197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return list.release(); 62197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 63197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 64197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if !ENABLE(OILPAN) 65197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void removeChildNodeList(ChildNodeList* list) 66197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 67197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(m_childNodeList == list); 68197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode())) 69197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return; 70197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_childNodeList = nullptr; 71197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 72197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 73197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void removeEmptyChildNodeList(EmptyNodeList* list) 74197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 75197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(m_childNodeList == list); 76197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode())) 77197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return; 78197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_childNodeList = nullptr; 79197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 80197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 81197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 82197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch struct NodeListAtomicCacheMapEntryHash { 83197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch static unsigned hash(const std::pair<unsigned char, StringImpl*>& entry) 84197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 85197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.first; 86197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 87197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch static bool equal(const std::pair<unsigned char, StringImpl*>& a, const std::pair<unsigned char, StringImpl*>& b) { return a == b; } 88197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl*>::Hash::safeToCompareToEmptyOrDeleted; 89197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch }; 90197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 91197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // Oilpan: keep a weak reference to the collection objects. 92197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // Explicit object unregistration in a non-Oilpan setting 93197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // on object destruction is replaced by the garbage collector 94197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // clearing out their weak reference. 95197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch typedef WillBeHeapHashMap<std::pair<unsigned char, StringImpl*>, RawPtrWillBeWeakMember<LiveNodeListBase>, NodeListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap; 96197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch typedef WillBeHeapHashMap<QualifiedName, RawPtrWillBeWeakMember<TagCollection> > TagCollectionCacheNS; 97197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 98197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch template<typename T> 99197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType collectionType, const AtomicString& name) 100197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 101197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, name), nullptr); 102197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (!result.isNewEntry) { 103197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(OILPAN) 104197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return static_cast<T*>(result.storedValue->value.get()); 105197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#else 106197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return static_cast<T*>(result.storedValue->value); 107197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 108197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 109197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 110197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtrWillBeRawPtr<T> list = T::create(node, collectionType, name); 111197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch result.storedValue->value = list.get(); 112197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return list.release(); 113197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 114197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 115197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch template<typename T> 116197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType collectionType) 117197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 118197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, starAtom), nullptr); 119197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (!result.isNewEntry) { 120197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if ENABLE(OILPAN) 121197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return static_cast<T*>(result.storedValue->value.get()); 122197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#else 123197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return static_cast<T*>(result.storedValue->value); 124197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 125197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 126197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 127197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtrWillBeRawPtr<T> list = T::create(node, collectionType); 128197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch result.storedValue->value = list.get(); 129197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return list.release(); 130197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 131197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 132197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch template<typename T> 133197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch T* cached(CollectionType collectionType) 134197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 135197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectionType, starAtom))); 136197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 137197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 138197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<TagCollection> addCache(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName) 139197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 140197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch QualifiedName name(nullAtom, localName, namespaceURI); 141197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name, nullptr); 142197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (!result.isNewEntry) 143197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return result.storedValue->value; 144197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 145197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RefPtrWillBeRawPtr<TagCollection> list = TagCollection::create(node, namespaceURI, localName); 146197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch result.storedValue->value = list.get(); 147197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return list.release(); 148197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 149197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 150197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if !ENABLE(OILPAN) 151197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void removeCache(LiveNodeListBase* list, CollectionType collectionType, const AtomicString& name = starAtom) 152197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 153197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, name))); 154197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode())) 155197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return; 156197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_atomicNameCaches.remove(namedNodeListKey(collectionType, name)); 157197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 158197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 159197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void removeCache(LiveNodeListBase* list, const AtomicString& namespaceURI, const AtomicString& localName) 160197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 161197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch QualifiedName name(nullAtom, localName, namespaceURI); 162197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(list == m_tagCollectionCacheNS.get(name)); 163197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode())) 164197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return; 165197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch m_tagCollectionCacheNS.remove(name); 166197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 167197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 168197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 169197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch static PassOwnPtrWillBeRawPtr<NodeListsNodeData> create() 170197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 171197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return adoptPtrWillBeNoop(new NodeListsNodeData); 172197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 173197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 174197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void invalidateCaches(const QualifiedName* attrName = 0); 175197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 176197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch bool isEmpty() const 177197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 178197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return !m_childNodeList && m_atomicNameCaches.isEmpty() && m_tagCollectionCacheNS.isEmpty(); 179197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 180197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 181197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void adoptTreeScope() 182197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 183197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch invalidateCaches(); 184197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 185197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 186197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void adoptDocument(Document& oldDocument, Document& newDocument) 187197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 188197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(oldDocument != newDocument); 189197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 190197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_atomicNameCaches.end(); 191197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCaches.begin(); it != atomicNameCacheEnd; ++it) { 192197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LiveNodeListBase* list = it->value; 193197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch list->didMoveToDocument(oldDocument, newDocument); 194197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 195197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 196197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch TagCollectionCacheNS::const_iterator tagEnd = m_tagCollectionCacheNS.end(); 197197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch for (TagCollectionCacheNS::const_iterator it = m_tagCollectionCacheNS.begin(); it != tagEnd; ++it) { 198197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LiveNodeListBase* list = it->value; 199197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(!list->isRootedAtDocument()); 200197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch list->didMoveToDocument(oldDocument, newDocument); 201197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 202197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 203197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 204197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void trace(Visitor*); 205197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 206197021e6b966cfb06891637935ef33fff06433d1Ben Murdochprivate: 207197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch NodeListsNodeData() 208197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch : m_childNodeList(nullptr) 209197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { } 210197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 211197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch std::pair<unsigned char, StringImpl*> namedNodeListKey(CollectionType type, const AtomicString& name) 212197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch { 213197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // Holding the raw StringImpl is safe because |name| is retained by the NodeList and the NodeList 214197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // is reponsible for removing itself from the cache on deletion. 215197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return std::pair<unsigned char, StringImpl*>(type, name.impl()); 216197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch } 217197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 218197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if !ENABLE(OILPAN) 219197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node&); 220197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 221197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 222197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch // Can be a ChildNodeList or an EmptyNodeList. 223197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch RawPtrWillBeWeakMember<NodeList> m_childNodeList; 224197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch NodeListAtomicNameCacheMap m_atomicNameCaches; 225197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch TagCollectionCacheNS m_tagCollectionCacheNS; 226197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}; 227197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 228197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#if !ENABLE(OILPAN) 229197021e6b966cfb06891637935ef33fff06433d1Ben Murdochinline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node& ownerNode) 230197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{ 231197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ASSERT(ownerNode.nodeLists() == this); 232197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_tagCollectionCacheNS.size() != 1) 233197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return false; 234197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch ownerNode.clearNodeLists(); 235197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch return true; 236197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch} 237197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif 238197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 239c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)template <typename Collection> 240c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)inline PassRefPtrWillBeRawPtr<Collection> ContainerNode::ensureCachedCollection(CollectionType type) 241c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 242c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) return ensureNodeLists().addCache<Collection>(*this, type); 243c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 244c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 245c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)template <typename Collection> 246c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)inline PassRefPtrWillBeRawPtr<Collection> ContainerNode::ensureCachedCollection(CollectionType type, const AtomicString& name) 247c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 248c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) return ensureNodeLists().addCache<Collection>(*this, type, name); 249c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 250c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 251c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)template <typename Collection> 252c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)inline PassRefPtrWillBeRawPtr<Collection> ContainerNode::ensureCachedCollection(CollectionType type, const AtomicString& namespaceURI, const AtomicString& localName) 253c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 254c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) ASSERT_UNUSED(type, type == TagCollectionType); 255c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) return ensureNodeLists().addCache(*this, namespaceURI, localName); 256c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 257c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 258c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)template <typename Collection> 259c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)inline Collection* ContainerNode::cachedCollection(CollectionType type) 260c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles){ 261c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) NodeListsNodeData* nodeLists = this->nodeLists(); 262c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) return nodeLists ? nodeLists->cached<Collection>(type) : 0; 263c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} 264c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 265c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 266197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch 267197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif // NodeListsNodeData_h 268