Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: Source/core/dom/NodeRareData.h

Issue 390043003: Move NodeListsNodeData class out of NodeRareData.h (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/NodeRareData.h
diff --git a/Source/core/dom/NodeRareData.h b/Source/core/dom/NodeRareData.h
index ef4cddd91b7c010748b5e05393f45683cbf3696a..19b0b8bb362939906cafe25c7f52188d69eaf372 100644
--- a/Source/core/dom/NodeRareData.h
+++ b/Source/core/dom/NodeRareData.h
@@ -22,213 +22,15 @@
#ifndef NodeRareData_h
#define NodeRareData_h
-#include "core/dom/ChildNodeList.h"
-#include "core/dom/EmptyNodeList.h"
-#include "core/dom/LiveNodeList.h"
#include "core/dom/MutationObserverRegistration.h"
-#include "core/dom/QualifiedName.h"
-#include "core/dom/TagCollection.h"
+#include "core/dom/NodeListsNodeData.h"
#include "platform/heap/Handle.h"
#include "wtf/HashSet.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
-#include "wtf/text/AtomicString.h"
-#include "wtf/text/StringHash.h"
namespace WebCore {
-class NodeListsNodeData FINAL : public NoBaseWillBeGarbageCollectedFinalized<NodeListsNodeData> {
- WTF_MAKE_NONCOPYABLE(NodeListsNodeData);
- WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
-public:
- void clearChildNodeListCache()
- {
- if (m_childNodeList && m_childNodeList->isChildNodeList())
- toChildNodeList(m_childNodeList)->invalidateCache();
- }
-
- PassRefPtrWillBeRawPtr<ChildNodeList> ensureChildNodeList(ContainerNode& node)
- {
- if (m_childNodeList)
- return toChildNodeList(m_childNodeList);
- RefPtrWillBeRawPtr<ChildNodeList> list = ChildNodeList::create(node);
- m_childNodeList = list.get();
- return list.release();
- }
-
- PassRefPtrWillBeRawPtr<EmptyNodeList> ensureEmptyChildNodeList(Node& node)
- {
- if (m_childNodeList)
- return toEmptyNodeList(m_childNodeList);
- RefPtrWillBeRawPtr<EmptyNodeList> list = EmptyNodeList::create(node);
- m_childNodeList = list.get();
- return list.release();
- }
-
-#if !ENABLE(OILPAN)
- void removeChildNodeList(ChildNodeList* list)
- {
- ASSERT(m_childNodeList == list);
- if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
- return;
- m_childNodeList = nullptr;
- }
-
- void removeEmptyChildNodeList(EmptyNodeList* list)
- {
- ASSERT(m_childNodeList == list);
- if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
- return;
- m_childNodeList = nullptr;
- }
-#endif
-
- struct NodeListAtomicCacheMapEntryHash {
- static unsigned hash(const std::pair<unsigned char, StringImpl*>& entry)
- {
- return DefaultHash<StringImpl*>::Hash::hash(entry.second) + entry.first;
- }
- static bool equal(const std::pair<unsigned char, StringImpl*>& a, const std::pair<unsigned char, StringImpl*>& b) { return a == b; }
- static const bool safeToCompareToEmptyOrDeleted = DefaultHash<StringImpl*>::Hash::safeToCompareToEmptyOrDeleted;
- };
-
- // Oilpan: keep a weak reference to the collection objects.
- // Explicit object unregistration in a non-Oilpan setting
- // on object destruction is replaced by the garbage collector
- // clearing out their weak reference.
- typedef WillBeHeapHashMap<std::pair<unsigned char, StringImpl*>, RawPtrWillBeWeakMember<LiveNodeListBase>, NodeListAtomicCacheMapEntryHash> NodeListAtomicNameCacheMap;
- typedef WillBeHeapHashMap<QualifiedName, RawPtrWillBeWeakMember<TagCollection> > TagCollectionCacheNS;
-
- template<typename T>
- PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType collectionType, const AtomicString& name)
- {
- NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, name), nullptr);
- if (!result.isNewEntry) {
-#if ENABLE(OILPAN)
- return static_cast<T*>(result.storedValue->value.get());
-#else
- return static_cast<T*>(result.storedValue->value);
-#endif
- }
-
- RefPtrWillBeRawPtr<T> list = T::create(node, collectionType, name);
- result.storedValue->value = list.get();
- return list.release();
- }
-
- template<typename T>
- PassRefPtrWillBeRawPtr<T> addCache(ContainerNode& node, CollectionType collectionType)
- {
- NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, starAtom), nullptr);
- if (!result.isNewEntry) {
-#if ENABLE(OILPAN)
- return static_cast<T*>(result.storedValue->value.get());
-#else
- return static_cast<T*>(result.storedValue->value);
-#endif
- }
-
- RefPtrWillBeRawPtr<T> list = T::create(node, collectionType);
- result.storedValue->value = list.get();
- return list.release();
- }
-
- template<typename T>
- T* cached(CollectionType collectionType)
- {
- return static_cast<T*>(m_atomicNameCaches.get(namedNodeListKey(collectionType, starAtom)));
- }
-
- PassRefPtrWillBeRawPtr<TagCollection> addCache(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName)
- {
- QualifiedName name(nullAtom, localName, namespaceURI);
- TagCollectionCacheNS::AddResult result = m_tagCollectionCacheNS.add(name, nullptr);
- if (!result.isNewEntry)
- return result.storedValue->value;
-
- RefPtrWillBeRawPtr<TagCollection> list = TagCollection::create(node, namespaceURI, localName);
- result.storedValue->value = list.get();
- return list.release();
- }
-
-#if !ENABLE(OILPAN)
- void removeCache(LiveNodeListBase* list, CollectionType collectionType, const AtomicString& name = starAtom)
- {
- ASSERT(list == m_atomicNameCaches.get(namedNodeListKey(collectionType, name)));
- if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
- return;
- m_atomicNameCaches.remove(namedNodeListKey(collectionType, name));
- }
-
- void removeCache(LiveNodeListBase* list, const AtomicString& namespaceURI, const AtomicString& localName)
- {
- QualifiedName name(nullAtom, localName, namespaceURI);
- ASSERT(list == m_tagCollectionCacheNS.get(name));
- if (deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(list->ownerNode()))
- return;
- m_tagCollectionCacheNS.remove(name);
- }
-#endif
-
- static PassOwnPtrWillBeRawPtr<NodeListsNodeData> create()
- {
- return adoptPtrWillBeNoop(new NodeListsNodeData);
- }
-
- void invalidateCaches(const QualifiedName* attrName = 0);
-
- bool isEmpty() const
- {
- return !m_childNodeList && m_atomicNameCaches.isEmpty() && m_tagCollectionCacheNS.isEmpty();
- }
-
- void adoptTreeScope()
- {
- invalidateCaches();
- }
-
- void adoptDocument(Document& oldDocument, Document& newDocument)
- {
- ASSERT(oldDocument != newDocument);
-
- NodeListAtomicNameCacheMap::const_iterator atomicNameCacheEnd = m_atomicNameCaches.end();
- for (NodeListAtomicNameCacheMap::const_iterator it = m_atomicNameCaches.begin(); it != atomicNameCacheEnd; ++it) {
- LiveNodeListBase* list = it->value;
- list->didMoveToDocument(oldDocument, newDocument);
- }
-
- TagCollectionCacheNS::const_iterator tagEnd = m_tagCollectionCacheNS.end();
- for (TagCollectionCacheNS::const_iterator it = m_tagCollectionCacheNS.begin(); it != tagEnd; ++it) {
- LiveNodeListBase* list = it->value;
- ASSERT(!list->isRootedAtDocument());
- list->didMoveToDocument(oldDocument, newDocument);
- }
- }
-
- void trace(Visitor*);
-
-private:
- NodeListsNodeData()
- : m_childNodeList(nullptr)
- { }
-
- std::pair<unsigned char, StringImpl*> namedNodeListKey(CollectionType type, const AtomicString& name)
- {
- // Holding the raw StringImpl is safe because |name| is retained by the NodeList and the NodeList
- // is reponsible for removing itself from the cache on deletion.
- return std::pair<unsigned char, StringImpl*>(type, name.impl());
- }
-
-#if !ENABLE(OILPAN)
- bool deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node&);
-#endif
-
- // Can be a ChildNodeList or an EmptyNodeList.
- RawPtrWillBeWeakMember<NodeList> m_childNodeList;
- NodeListAtomicNameCacheMap m_atomicNameCaches;
- TagCollectionCacheNS m_tagCollectionCacheNS;
-};
-
class NodeMutationObserverData FINAL : public NoBaseWillBeGarbageCollected<NodeMutationObserverData> {
WTF_MAKE_NONCOPYABLE(NodeMutationObserverData);
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
@@ -327,17 +129,6 @@ protected:
unsigned m_isElementRareData : 1;
};
-#if !ENABLE(OILPAN)
-inline bool NodeListsNodeData::deleteThisAndUpdateNodeRareDataIfAboutToRemoveLastList(Node& ownerNode)
-{
- ASSERT(ownerNode.nodeLists() == this);
- if ((m_childNodeList ? 1 : 0) + m_atomicNameCaches.size() + m_tagCollectionCacheNS.size() != 1)
- return false;
- ownerNode.clearNodeLists();
- return true;
-}
-#endif
-
} // namespace WebCore
#endif // NodeRareData_h

Powered by Google App Engine
This is Rietveld 408576698