- Revision
- 137003
- Author
- [email protected]
- Date
- 2012-12-07 17:17:36 -0800 (Fri, 07 Dec 2012)
Log Message
Shrink the size of NodeRareData by moving pointers into separate objects
https://bugs.webkit.org/show_bug.cgi?id=104312
Reviewed by Andreas Kling.
This patch does three things:
1. Move ChildNodeList back into NodeListsNodeData.
2. Move m_mutationObserverRegistry & m_transientMutationObserverRegistry into a separate object owned by NodeRareData.
3. Move m_itemProp, m_itemRef, m_itemType & into a separate object owned by NodeRareData.
Moving m_childNodeList from NodeRareData to NodeListsNodeData also has a nice side-effect of making ChildNodeList
behave more like other LiveNodeLists.
This patch also fixes Mac build when microdata is enabled.
There should be no user-visible behavior change.
* dom/ChildNodeList.cpp:
(WebCore::ChildNodeList::~ChildNodeList):
* dom/Node.cpp:
(WebCore::Node::childNodes): Moved the code to create ChildNodeList into NodeListsNodeData to match other node lists.
(WebCore::Node::invalidateNodeListCachesInAncestors):
(WebCore): Removed removeCachedChildNodeList.
* dom/Node.h:
(Node):
* dom/NodeRareData.cpp:
(WebCore): Assert the size of NodeRareData at compilation time.
(WebCore::NodeListsNodeData::reportMemoryUsage):
(WebCore::NodeRareData::reportMemoryUsage):
* dom/NodeRareData.h:
(WebCore::NodeListsNodeData::clearChildNodeListCache): Moved from NodeRareData.
(WebCore::NodeListsNodeData::ensureChildNodeList): Extracted from Node::childNodes.
(WebCore::NodeListsNodeData::removeChildNodeList): Added.
(WebCore::NodeListsNodeData::NodeListsNodeData): Initialize m_childNodeList.
(WebCore::NodeRareData::NodeMutationObserverData): Extracted from NodeRareData.
(WebCore::NodeRareData::NodeMutationObserverData::create):
(WebCore::NodeRareData::NodeMicroDataTokenLists): Ditto.
(WebCore::NodeRareData::NodeMicroDataTokenLists::create):
(WebCore::NodeRareData::NodeRareData):
(WebCore::NodeRareData::ensureNodeLists): Merged setNodeLists since it's not called elsewhere.
(WebCore::NodeRareData::mutationObserverRegistry):
(WebCore::NodeRareData::ensureMutationObserverRegistry): Added.
(WebCore::NodeRareData::transientMutationObserverRegistry):
(WebCore::NodeRareData::ensureTransientMutationObserverRegistry):
(WebCore::NodeRareData::ensureMicroDataTokenLists):
(NodeRareData):
(WebCore::NodeRareData::itemProp):
(WebCore::NodeRareData::setItemProp):
(WebCore::NodeRareData::itemRef):
(WebCore::NodeRareData::setItemRef):
(WebCore::NodeRareData::itemType):
(WebCore::NodeRareData::setItemType):
* html/HTMLPropertiesCollection.cpp:
(WebCore::HTMLPropertiesCollection::propertyNodeList): Renamed from namedItem since its return type, PropertyNodeList,
is different from that, Node, of LiveNodeList::namedItem. It was shadowing the function name instead of overriding.
* html/HTMLPropertiesCollection.h:
(HTMLPropertiesCollection):
* html/HTMLPropertiesCollection.idl:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (137002 => 137003)
--- trunk/Source/WebCore/ChangeLog 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/ChangeLog 2012-12-08 01:17:36 UTC (rev 137003)
@@ -1,3 +1,64 @@
+2012-12-06 Ryosuke Niwa <[email protected]>
+
+ Shrink the size of NodeRareData by moving pointers into separate objects
+ https://bugs.webkit.org/show_bug.cgi?id=104312
+
+ Reviewed by Andreas Kling.
+
+ This patch does three things:
+ 1. Move ChildNodeList back into NodeListsNodeData.
+ 2. Move m_mutationObserverRegistry & m_transientMutationObserverRegistry into a separate object owned by NodeRareData.
+ 3. Move m_itemProp, m_itemRef, m_itemType & into a separate object owned by NodeRareData.
+
+ Moving m_childNodeList from NodeRareData to NodeListsNodeData also has a nice side-effect of making ChildNodeList
+ behave more like other LiveNodeLists.
+
+ This patch also fixes Mac build when microdata is enabled.
+
+ There should be no user-visible behavior change.
+
+ * dom/ChildNodeList.cpp:
+ (WebCore::ChildNodeList::~ChildNodeList):
+ * dom/Node.cpp:
+ (WebCore::Node::childNodes): Moved the code to create ChildNodeList into NodeListsNodeData to match other node lists.
+ (WebCore::Node::invalidateNodeListCachesInAncestors):
+ (WebCore): Removed removeCachedChildNodeList.
+ * dom/Node.h:
+ (Node):
+ * dom/NodeRareData.cpp:
+ (WebCore): Assert the size of NodeRareData at compilation time.
+ (WebCore::NodeListsNodeData::reportMemoryUsage):
+ (WebCore::NodeRareData::reportMemoryUsage):
+ * dom/NodeRareData.h:
+ (WebCore::NodeListsNodeData::clearChildNodeListCache): Moved from NodeRareData.
+ (WebCore::NodeListsNodeData::ensureChildNodeList): Extracted from Node::childNodes.
+ (WebCore::NodeListsNodeData::removeChildNodeList): Added.
+ (WebCore::NodeListsNodeData::NodeListsNodeData): Initialize m_childNodeList.
+ (WebCore::NodeRareData::NodeMutationObserverData): Extracted from NodeRareData.
+ (WebCore::NodeRareData::NodeMutationObserverData::create):
+ (WebCore::NodeRareData::NodeMicroDataTokenLists): Ditto.
+ (WebCore::NodeRareData::NodeMicroDataTokenLists::create):
+ (WebCore::NodeRareData::NodeRareData):
+ (WebCore::NodeRareData::ensureNodeLists): Merged setNodeLists since it's not called elsewhere.
+ (WebCore::NodeRareData::mutationObserverRegistry):
+ (WebCore::NodeRareData::ensureMutationObserverRegistry): Added.
+ (WebCore::NodeRareData::transientMutationObserverRegistry):
+ (WebCore::NodeRareData::ensureTransientMutationObserverRegistry):
+ (WebCore::NodeRareData::ensureMicroDataTokenLists):
+ (NodeRareData):
+ (WebCore::NodeRareData::itemProp):
+ (WebCore::NodeRareData::setItemProp):
+ (WebCore::NodeRareData::itemRef):
+ (WebCore::NodeRareData::setItemRef):
+ (WebCore::NodeRareData::itemType):
+ (WebCore::NodeRareData::setItemType):
+ * html/HTMLPropertiesCollection.cpp:
+ (WebCore::HTMLPropertiesCollection::propertyNodeList): Renamed from namedItem since its return type, PropertyNodeList,
+ is different from that, Node, of LiveNodeList::namedItem. It was shadowing the function name instead of overriding.
+ * html/HTMLPropertiesCollection.h:
+ (HTMLPropertiesCollection):
+ * html/HTMLPropertiesCollection.idl:
+
2012-12-07 Sheriff Bot <[email protected]>
Unreviewed, rolling out r136993.
Modified: trunk/Source/WebCore/dom/ChildNodeList.cpp (137002 => 137003)
--- trunk/Source/WebCore/dom/ChildNodeList.cpp 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/dom/ChildNodeList.cpp 2012-12-08 01:17:36 UTC (rev 137003)
@@ -24,6 +24,7 @@
#include "ChildNodeList.h"
#include "Element.h"
+#include "NodeRareData.h"
namespace WebCore {
@@ -34,7 +35,7 @@
ChildNodeList::~ChildNodeList()
{
- ownerNode()->removeCachedChildNodeList();
+ ownerNode()->nodeLists()->removeChildNodeList(this);
}
bool ChildNodeList::nodeMatches(Element* testNode) const
Modified: trunk/Source/WebCore/dom/Node.cpp (137002 => 137003)
--- trunk/Source/WebCore/dom/Node.cpp 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/dom/Node.cpp 2012-12-08 01:17:36 UTC (rev 137003)
@@ -560,13 +560,7 @@
PassRefPtr<NodeList> Node::childNodes()
{
- NodeRareData* data = ""
- if (data->childNodeList())
- return PassRefPtr<NodeList>(data->childNodeList());
-
- RefPtr<ChildNodeList> list = ChildNodeList::create(this);
- data->setChildNodeList(list.get());
- return list.release();
+ return ensureRareData()->ensureNodeLists()->ensureChildNodeList(this);
}
Node *Node::lastDescendant() const
@@ -1017,8 +1011,10 @@
void Node::invalidateNodeListCachesInAncestors(const QualifiedName* attrName, Element* attributeOwnerElement)
{
- if (hasRareData() && (!attrName || isAttributeNode()))
- rareData()->clearChildNodeListCache();
+ if (hasRareData() && (!attrName || isAttributeNode())) {
+ if (NodeListsNodeData* lists = rareData()->nodeLists())
+ lists->clearChildNodeListCache();
+ }
// Modifications to attributes that are not associated with an Element can't invalidate NodeList caches.
if (attrName && !attributeOwnerElement)
@@ -1043,12 +1039,6 @@
return hasRareData() ? rareData()->nodeLists() : 0;
}
-void Node::removeCachedChildNodeList()
-{
- ASSERT(rareData());
- rareData()->setChildNodeList(0);
-}
-
Node* Node::traverseNextAncestorSibling() const
{
ASSERT(!nextSibling());
Modified: trunk/Source/WebCore/dom/Node.h (137002 => 137003)
--- trunk/Source/WebCore/dom/Node.h 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/dom/Node.h 2012-12-08 01:17:36 UTC (rev 137003)
@@ -601,7 +601,6 @@
void invalidateNodeListCachesInAncestors(const QualifiedName* attrName = 0, Element* attributeOwnerElement = 0);
NodeListsNodeData* nodeLists();
- void removeCachedChildNodeList();
PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
Modified: trunk/Source/WebCore/dom/NodeRareData.cpp (137002 => 137003)
--- trunk/Source/WebCore/dom/NodeRareData.cpp 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/dom/NodeRareData.cpp 2012-12-08 01:17:36 UTC (rev 137003)
@@ -38,9 +38,24 @@
namespace WebCore {
+struct SameSizeAsNodeRareData {
+ void* m_pointer[4];
+ unsigned m_indicesAndBitfields[2];
+
+#if ENABLE(MUTATION_OBSERVERS)
+ void* m_mutationObserver;
+#endif
+
+#if ENABLE(MICRODATA)
+ void* m_microData;
+#endif
+};
+COMPILE_ASSERT(sizeof(NodeRareData) == sizeof(SameSizeAsNodeRareData), NodeRareDataShouldStaySmall);
+
void NodeListsNodeData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
+ info.addMember(m_childNodeList);
info.addMember(m_atomicNameCaches);
info.addMember(m_nameCaches);
info.addMember(m_tagNodeListCacheNS);
@@ -51,17 +66,13 @@
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
info.addMember(treeScope());
info.addMember(m_nodeLists);
- info.addMember(m_childNodeList);
#if ENABLE(MUTATION_OBSERVERS)
- info.addMember(m_mutationObserverRegistry);
- info.addMember(m_transientMutationObserverRegistry);
+ info.addMember(m_mutationObserverData);
#endif
#if ENABLE(MICRODATA)
- info.addMember(m_itemProp);
- info.addMember(m_itemRef);
- info.addMember(m_itemType);
+ info.addMember(m_microDataTokenLists);
#endif
}
Modified: trunk/Source/WebCore/dom/NodeRareData.h (137002 => 137003)
--- trunk/Source/WebCore/dom/NodeRareData.h 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/dom/NodeRareData.h 2012-12-08 01:17:36 UTC (rev 137003)
@@ -49,6 +49,27 @@
class NodeListsNodeData {
WTF_MAKE_NONCOPYABLE(NodeListsNodeData); WTF_MAKE_FAST_ALLOCATED;
public:
+ void clearChildNodeListCache()
+ {
+ if (m_childNodeList)
+ m_childNodeList->invalidateCache();
+ }
+
+ PassRefPtr<ChildNodeList> ensureChildNodeList(Node* node)
+ {
+ if (m_childNodeList)
+ return m_childNodeList;
+ RefPtr<ChildNodeList> list = ChildNodeList::create(node);
+ m_childNodeList = list.get();
+ return list.release();
+ }
+
+ void removeChildNodeList(ChildNodeList* list)
+ {
+ ASSERT_UNUSED(list, m_childNodeList = list);
+ m_childNodeList = 0;
+ }
+
template <typename StringType>
struct NodeListCacheMapEntryHash {
static unsigned hash(const std::pair<unsigned char, StringType>& entry)
@@ -75,6 +96,7 @@
return list.release();
}
+ // FIXME: This function should be renamed since it doesn't have an atomic name.
template<typename T>
PassRefPtr<T> addCacheWithAtomicName(Node* node, CollectionType collectionType)
{
@@ -179,7 +201,9 @@
void reportMemoryUsage(MemoryObjectInfo*) const;
private:
- NodeListsNodeData() { }
+ NodeListsNodeData()
+ : m_childNodeList(0)
+ { }
std::pair<unsigned char, AtomicString> namedNodeListKey(CollectionType type, const AtomicString& name)
{
@@ -191,6 +215,9 @@
return std::pair<unsigned char, String>(type, name);
}
+ // FIXME: m_childNodeList should be merged into m_atomicNameCaches or at least be shared with HTMLCollection returned by Element::children
+ // but it's tricky because invalidateCaches shouldn't invalidate this cache and adoptTreeScope shouldn't call registerNodeList or unregisterNodeList.
+ ChildNodeList* m_childNodeList;
NodeListAtomicNameCacheMap m_atomicNameCaches;
NodeListNameCacheMap m_nameCaches;
TagNodeListCacheNS m_tagNodeListCacheNS;
@@ -198,10 +225,25 @@
class NodeRareData : public NodeRareDataBase {
WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
+
+ struct NodeMutationObserverData {
+ Vector<OwnPtr<MutationObserverRegistration> > m_registry;
+ HashSet<MutationObserverRegistration*> m_transientRegistry;
+
+ static PassOwnPtr<NodeMutationObserverData> create() { return adoptPtr(new NodeMutationObserverData); }
+ };
+
+ struct NodeMicroDataTokenLists {
+ RefPtr<DOMSettableTokenList> m_itemProp;
+ RefPtr<DOMSettableTokenList> m_itemRef;
+ RefPtr<DOMSettableTokenList> m_itemType;
+
+ static PassOwnPtr<NodeMicroDataTokenLists> create() { return adoptPtr(new NodeMicroDataTokenLists); }
+ };
+
public:
NodeRareData(Document* document)
: NodeRareDataBase(document)
- , m_childNodeList(0)
, m_tabIndex(0)
, m_childIndex(0)
, m_tabIndexWasSetExplicitly(false)
@@ -231,93 +273,91 @@
}
void clearNodeLists() { m_nodeLists.clear(); }
- void setNodeLists(PassOwnPtr<NodeListsNodeData> lists) { m_nodeLists = lists; }
NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
NodeListsNodeData* ensureNodeLists()
{
if (!m_nodeLists)
- setNodeLists(NodeListsNodeData::create());
+ m_nodeLists = NodeListsNodeData::create();
return m_nodeLists.get();
}
- void clearChildNodeListCache()
- {
- if (m_childNodeList)
- m_childNodeList->invalidateCache();
- }
- ChildNodeList* childNodeList() const { return m_childNodeList; }
- void setChildNodeList(ChildNodeList* list) { m_childNodeList = list; }
-
short tabIndex() const { return m_tabIndex; }
void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
void clearTabIndexExplicitly() { m_tabIndex = 0; m_tabIndexWasSetExplicitly = false; }
#if ENABLE(MUTATION_OBSERVERS)
- Vector<OwnPtr<MutationObserverRegistration> >* mutationObserverRegistry() { return m_mutationObserverRegistry.get(); }
+ Vector<OwnPtr<MutationObserverRegistration> >* mutationObserverRegistry() { return m_mutationObserverData ? &m_mutationObserverData->m_registry : 0; }
Vector<OwnPtr<MutationObserverRegistration> >* ensureMutationObserverRegistry()
{
- if (!m_mutationObserverRegistry)
- m_mutationObserverRegistry = adoptPtr(new Vector<OwnPtr<MutationObserverRegistration> >);
- return m_mutationObserverRegistry.get();
+ if (!m_mutationObserverData)
+ m_mutationObserverData = NodeMutationObserverData::create();
+ return &m_mutationObserverData->m_registry;
}
- HashSet<MutationObserverRegistration*>* transientMutationObserverRegistry() { return m_transientMutationObserverRegistry.get(); }
+ HashSet<MutationObserverRegistration*>* transientMutationObserverRegistry() { return m_mutationObserverData ? &m_mutationObserverData->m_transientRegistry : 0; }
HashSet<MutationObserverRegistration*>* ensureTransientMutationObserverRegistry()
{
- if (!m_transientMutationObserverRegistry)
- m_transientMutationObserverRegistry = adoptPtr(new HashSet<MutationObserverRegistration*>);
- return m_transientMutationObserverRegistry.get();
+ if (!m_mutationObserverData)
+ m_mutationObserverData = NodeMutationObserverData::create();
+ return &m_mutationObserverData->m_transientRegistry;
}
#endif
#if ENABLE(MICRODATA)
+ NodeMicroDataTokenLists* ensureMicroDataTokenLists() const
+ {
+ if (!m_microDataTokenLists)
+ m_microDataTokenLists = NodeMicroDataTokenLists::create();
+ return m_microDataTokenLists.get();
+ }
+
DOMSettableTokenList* itemProp() const
{
- if (!m_itemProp)
- m_itemProp = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemProp)
+ m_microDataTokenLists->m_itemProp = DOMSettableTokenList::create();
- return m_itemProp.get();
+ return m_microDataTokenLists->m_itemProp.get();
}
void setItemProp(const String& value)
{
- if (!m_itemProp)
- m_itemProp = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemProp)
+ m_microDataTokenLists->m_itemProp = DOMSettableTokenList::create();
- m_itemProp->setValue(value);
+ m_microDataTokenLists->m_itemProp->setValue(value);
}
DOMSettableTokenList* itemRef() const
{
- if (!m_itemRef)
- m_itemRef = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemRef)
+ m_microDataTokenLists->m_itemRef = DOMSettableTokenList::create();
- return m_itemRef.get();
+ return m_microDataTokenLists->m_itemRef.get();
}
void setItemRef(const String& value)
{
- if (!m_itemRef)
- m_itemRef = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemRef)
+ m_microDataTokenLists->m_itemRef = DOMSettableTokenList::create();
- m_itemRef->setValue(value);
+ m_microDataTokenLists->m_itemRef->setValue(value);
}
DOMSettableTokenList* itemType() const
{
- if (!m_itemType)
- m_itemType = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemType)
+ m_microDataTokenLists->m_itemType = DOMSettableTokenList::create();
- return m_itemType.get();
+ return m_microDataTokenLists->m_itemType.get();
}
void setItemType(const String& value)
{
- if (!m_itemType)
- m_itemType = DOMSettableTokenList::create();
+ if (!ensureMicroDataTokenLists()->m_itemType)
+ m_microDataTokenLists->m_itemType = DOMSettableTokenList::create();
- m_itemType->setValue(value);
+ m_microDataTokenLists->m_itemType->setValue(value);
}
#endif
@@ -327,8 +367,6 @@
virtual void reportMemoryUsage(MemoryObjectInfo*) const;
protected:
- OwnPtr<NodeListsNodeData> m_nodeLists;
- ChildNodeList* m_childNodeList;
short m_tabIndex;
unsigned short m_childIndex;
bool m_tabIndexWasSetExplicitly : 1;
@@ -354,15 +392,15 @@
bool m_childrenAffectedByForwardPositionalRules : 1;
bool m_childrenAffectedByBackwardPositionalRules : 1;
+private:
+ OwnPtr<NodeListsNodeData> m_nodeLists;
+
#if ENABLE(MUTATION_OBSERVERS)
- OwnPtr<Vector<OwnPtr<MutationObserverRegistration> > > m_mutationObserverRegistry;
- OwnPtr<HashSet<MutationObserverRegistration*> > m_transientMutationObserverRegistry;
+ OwnPtr<NodeMutationObserverData> m_mutationObserverData;
#endif
#if ENABLE(MICRODATA)
- mutable RefPtr<DOMSettableTokenList> m_itemProp;
- mutable RefPtr<DOMSettableTokenList> m_itemRef;
- mutable RefPtr<DOMSettableTokenList> m_itemType;
+ mutable OwnPtr<NodeMicroDataTokenLists> m_microDataTokenLists;
#endif
};
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp (137002 => 137003)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp 2012-12-08 01:17:36 UTC (rev 137003)
@@ -135,7 +135,7 @@
return m_propertyNames;
}
-PassRefPtr<PropertyNodeList> HTMLPropertiesCollection::namedItem(const String& name) const
+PassRefPtr<PropertyNodeList> HTMLPropertiesCollection::propertyNodeList(const String& name) const
{
return ownerNode()->propertyNodeList(name);
}
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.h (137002 => 137003)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.h 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.h 2012-12-08 01:17:36 UTC (rev 137003)
@@ -49,7 +49,7 @@
void updateRefElements() const;
PassRefPtr<DOMStringList> names() const;
- virtual PassRefPtr<PropertyNodeList> namedItem(const String&) const OVERRIDE;
+ virtual PassRefPtr<PropertyNodeList> propertyNodeList(const String&) const;
virtual bool hasNamedItem(const AtomicString&) const OVERRIDE;
void invalidateCache() const
Modified: trunk/Source/WebCore/html/HTMLPropertiesCollection.idl (137002 => 137003)
--- trunk/Source/WebCore/html/HTMLPropertiesCollection.idl 2012-12-08 01:05:32 UTC (rev 137002)
+++ trunk/Source/WebCore/html/HTMLPropertiesCollection.idl 2012-12-08 01:17:36 UTC (rev 137003)
@@ -38,5 +38,5 @@
Node item(in unsigned long index);
readonly attribute DOMStringList names;
- PropertyNodeList namedItem(in DOMString name);
+ [ImplementedAs=propertyNodeList] PropertyNodeList namedItem(in DOMString name);
};