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

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

Issue 10695128: Merge 120979 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1180/
Patch Set: Created 8 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
« no previous file with comments | « Source/WebCore/dom/Node.cpp ('k') | Source/WebCore/dom/TagNodeList.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/dom/NodeRareData.h
===================================================================
--- Source/WebCore/dom/NodeRareData.h (revision 122245)
+++ Source/WebCore/dom/NodeRareData.h (working copy)
@@ -23,11 +23,9 @@
#define NodeRareData_h
#include "ChildNodeList.h"
-#include "ClassNodeList.h"
#include "DOMSettableTokenList.h"
#include "DynamicNodeList.h"
#include "MutationObserverRegistration.h"
-#include "NameNodeList.h"
#include "QualifiedName.h"
#include "TagNodeList.h"
#include "WebKitMutationObserver.h"
@@ -51,40 +49,92 @@
struct NodeListsNodeData {
WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED;
public:
- typedef HashMap<String, ClassNodeList*> ClassNodeListCache;
- ClassNodeListCache m_classNodeListCache;
+ typedef HashMap<std::pair<unsigned short, AtomicString>, DynamicSubtreeNodeList*> NodeListAtomicNameCacheMap;
+ typedef HashMap<std::pair<unsigned short, String>, DynamicSubtreeNodeList*> NodeListNameCacheMap;
+ typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS;
- typedef HashMap<String, NameNodeList*> NameNodeListCache;
- NameNodeListCache m_nameNodeListCache;
-
- typedef HashMap<AtomicString, TagNodeList*> TagNodeListCache;
- TagNodeListCache m_tagNodeListCache;
+ template<typename T>
+ PassRefPtr<T> addCacheWithAtomicName(Node* node, DynamicNodeList::NodeListType listType, const AtomicString& name)
+ {
+ NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(listType, name), 0);
+ if (!result.isNewEntry)
+ return static_cast<T*>(result.iterator->second);
- typedef HashMap<RefPtr<QualifiedName::QualifiedNameImpl>, TagNodeList*> TagNodeListCacheNS;
- TagNodeListCacheNS m_tagNodeListCacheNS;
+ RefPtr<T> list = T::create(node, name);
+ result.iterator->second = list.get();
+ return list.release();
+ }
-#if ENABLE(MICRODATA)
- typedef HashMap<String, MicroDataItemList*> MicroDataItemListCache;
- MicroDataItemListCache m_microDataItemListCache;
-#endif
+ template<typename T>
+ PassRefPtr<T> addCacheWithName(Node* node, DynamicNodeList::NodeListType listType, const String& name)
+ {
+ NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListKey(listType, name), 0);
+ if (!result.isNewEntry)
+ return static_cast<T*>(result.iterator->second);
- LabelsNodeList* m_labelsNodeListCache;
+ RefPtr<T> list = T::create(node, name);
+ result.iterator->second = list.get();
+ return list.release();
+ }
- typedef HashMap<String, RadioNodeList*> RadioNodeListCache;
- RadioNodeListCache m_radioNodeListCache;
+ PassRefPtr<TagNodeList> addCacheWithQualifiedName(Node* node, const AtomicString& namespaceURI, const AtomicString& localName)
+ {
+ QualifiedName name(nullAtom, localName, namespaceURI);
+ TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, 0);
+ if (!result.isNewEntry)
+ return result.iterator->second;
+ RefPtr<TagNodeList> list = TagNodeList::create(node, namespaceURI, localName);
+ result.iterator->second = list.get();
+ return list.release();
+ }
+
+ void removeCacheWithAtomicName(DynamicSubtreeNodeList* list, DynamicNodeList::NodeListType listType, const AtomicString& name)
+ {
+ ASSERT_UNUSED(list, list == m_atomicNameCaches.get(namedNodeListKey(listType, name)));
+ m_atomicNameCaches.remove(namedNodeListKey(listType, name));
+ }
+
+ void removeCacheWithName(DynamicSubtreeNodeList* list, DynamicNodeList::NodeListType listType, const String& name)
+ {
+ ASSERT_UNUSED(list, list == m_nameCaches.get(namedNodeListKey(listType, name)));
+ m_nameCaches.remove(namedNodeListKey(listType, name));
+ }
+
+ void removeCacheWithQualifiedName(DynamicSubtreeNodeList* list, const AtomicString& namespaceURI, const AtomicString& localName)
+ {
+ QualifiedName name(nullAtom, localName, namespaceURI);
+ ASSERT_UNUSED(list, list == m_tagNodeListCacheNS.get(name));
+ m_tagNodeListCacheNS.remove(name);
+ }
+
static PassOwnPtr<NodeListsNodeData> create()
{
return adoptPtr(new NodeListsNodeData);
}
- void invalidateCaches();
- void invalidateCachesThatDependOnAttributes();
+ void invalidateCaches(const QualifiedName* attrName = 0);
+ bool isEmpty() const
+ {
+ return m_atomicNameCaches.isEmpty() && m_nameCaches.isEmpty() && m_tagNodeListCacheNS.isEmpty();
+ }
- bool isEmpty() const;
+private:
+ NodeListsNodeData() { }
-private:
- NodeListsNodeData() : m_labelsNodeListCache(0) {}
+ std::pair<unsigned short, AtomicString> namedNodeListKey(DynamicNodeList::NodeListType listType, const AtomicString& name)
+ {
+ return std::pair<unsigned short, AtomicString>(listType, name);
+ }
+
+ std::pair<unsigned short, String> namedNodeListKey(DynamicNodeList::NodeListType listType, const String& name)
+ {
+ return std::pair<unsigned short, String>(listType, name);
+ }
+
+ NodeListAtomicNameCacheMap m_atomicNameCaches;
+ NodeListNameCacheMap m_nameCaches;
+ TagNodeListCacheNS m_tagNodeListCacheNS;
};
class NodeRareData {
« no previous file with comments | « Source/WebCore/dom/Node.cpp ('k') | Source/WebCore/dom/TagNodeList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698