Simplify treeScope and setTreeScope
https://bugs.webkit.org/show_bug.cgi?id=103708
Patch by Elliott Sprehn <esprehn@gmail.com> on 2012-12-02
Reviewed by Hajime Morita.
By making the default treeScope in NodeRareData the document and then
moving the m_treeScope field to NodeRareDataBase we can make treeScope
inline and make setTreeScope much simpler.
There's also no reason to save calls to rareData() now that the map has
been eliminated by r133372 so we can eliminate the return value from
setTreeScope.
No new tests, just refactoring.
* WebCore.exp.in:
* dom/Document.h:
(WebCore::Node::treeScope):
(WebCore):
* dom/Element.cpp:
(WebCore::Element::createRareData):
* dom/ElementRareData.h:
(ElementRareData):
(WebCore::ElementRareData::ElementRareData):
* dom/Node.cpp:
(WebCore::Node::setTreeScope):
(WebCore::Node::createRareData):
* dom/Node.h:
(NodeRareDataBase):
(WebCore::NodeRareDataBase::treeScope):
(WebCore::NodeRareDataBase::setTreeScope):
(WebCore::NodeRareDataBase::NodeRareDataBase):
(Node):
* dom/NodeRareData.cpp:
(WebCore::NodeRareData::reportMemoryUsage):
* dom/NodeRareData.h:
(WebCore::NodeRareData::NodeRareData):
(NodeRareData):
* dom/TreeScopeAdopter.cpp:
(WebCore::TreeScopeAdopter::moveTreeToNewScope):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@136328 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index a68fcf3..d02ebfd 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,46 @@
+2012-12-02 Elliott Sprehn <esprehn@gmail.com>
+
+ Simplify treeScope and setTreeScope
+ https://bugs.webkit.org/show_bug.cgi?id=103708
+
+ Reviewed by Hajime Morita.
+
+ By making the default treeScope in NodeRareData the document and then
+ moving the m_treeScope field to NodeRareDataBase we can make treeScope
+ inline and make setTreeScope much simpler.
+
+ There's also no reason to save calls to rareData() now that the map has
+ been eliminated by r133372 so we can eliminate the return value from
+ setTreeScope.
+
+ No new tests, just refactoring.
+
+ * WebCore.exp.in:
+ * dom/Document.h:
+ (WebCore::Node::treeScope):
+ (WebCore):
+ * dom/Element.cpp:
+ (WebCore::Element::createRareData):
+ * dom/ElementRareData.h:
+ (ElementRareData):
+ (WebCore::ElementRareData::ElementRareData):
+ * dom/Node.cpp:
+ (WebCore::Node::setTreeScope):
+ (WebCore::Node::createRareData):
+ * dom/Node.h:
+ (NodeRareDataBase):
+ (WebCore::NodeRareDataBase::treeScope):
+ (WebCore::NodeRareDataBase::setTreeScope):
+ (WebCore::NodeRareDataBase::NodeRareDataBase):
+ (Node):
+ * dom/NodeRareData.cpp:
+ (WebCore::NodeRareData::reportMemoryUsage):
+ * dom/NodeRareData.h:
+ (WebCore::NodeRareData::NodeRareData):
+ (NodeRareData):
+ * dom/TreeScopeAdopter.cpp:
+ (WebCore::TreeScopeAdopter::moveTreeToNewScope):
+
2012-12-02 Justin Novosad <junov@google.com>
Fix occlusion culling logic to handle css background layer clipping
diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in
index 53c7c83..9395b48 100644
--- a/Source/WebCore/WebCore.exp.in
+++ b/Source/WebCore/WebCore.exp.in
@@ -1363,7 +1363,6 @@
__ZNK7WebCore4Node27traverseNextAncestorSiblingEv
__ZNK7WebCore4Node31numberOfScopedHTMLStyleChildrenEv
__ZNK7WebCore4Node9nodeIndexEv
-__ZNK7WebCore4Node9treeScopeEv
__ZNK7WebCore4Page10pluginDataEv
__ZNK7WebCore4Page14renderTreeSizeEv
__ZNK7WebCore4Page15backForwardListEv
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 4e26716..d697ce3 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -1538,6 +1538,11 @@
return this == m_document;
}
+inline TreeScope* Node::treeScope() const
+{
+ return hasRareData() ? m_data.m_rareData->treeScope() : documentInternal();
+}
+
inline Node::Node(Document* document, ConstructionType type)
: m_nodeFlags(type)
, m_document(document)
diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp
index b7d0e59..ce1d242 100644
--- a/Source/WebCore/dom/Element.cpp
+++ b/Source/WebCore/dom/Element.cpp
@@ -209,7 +209,7 @@
OwnPtr<NodeRareData> Element::createRareData()
{
- return adoptPtr(new ElementRareData);
+ return adoptPtr(new ElementRareData(documentInternal()));
}
DEFINE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(Element, blur);
diff --git a/Source/WebCore/dom/ElementRareData.h b/Source/WebCore/dom/ElementRareData.h
index 9e4ef1b..dc62df6 100644
--- a/Source/WebCore/dom/ElementRareData.h
+++ b/Source/WebCore/dom/ElementRareData.h
@@ -34,7 +34,7 @@
class ElementRareData : public NodeRareData {
public:
- ElementRareData();
+ ElementRareData(Document*);
virtual ~ElementRareData();
void resetComputedStyle();
@@ -91,8 +91,9 @@
return IntSize(LayoutUnit::max(), LayoutUnit::max());
}
-inline ElementRareData::ElementRareData()
- : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
+inline ElementRareData::ElementRareData(Document* document)
+ : NodeRareData(document)
+ , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
{
}
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index 1d9dfc4..d2fbb16 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -439,30 +439,12 @@
m_document = document;
}
-NodeRareData* Node::setTreeScope(TreeScope* scope)
+void Node::setTreeScope(TreeScope* scope)
{
- if (!scope) {
- if (hasRareData()) {
- NodeRareData* data = rareData();
- data->setTreeScope(0);
- return data;
- }
+ if (!hasRareData() && scope->rootNode()->isDocumentNode())
+ return;
- return 0;
- }
-
- NodeRareData* data = ensureRareData();
- data->setTreeScope(scope);
- return data;
-}
-
-TreeScope* Node::treeScope() const
-{
- // FIXME: Using m_document directly is not good -> see comment with document() in the header file.
- if (!hasRareData())
- return m_document;
- TreeScope* scope = rareData()->treeScope();
- return scope ? scope : m_document;
+ ensureRareData()->setTreeScope(scope);
}
NodeRareData* Node::rareData() const
@@ -486,7 +468,7 @@
OwnPtr<NodeRareData> Node::createRareData()
{
- return adoptPtr(new NodeRareData);
+ return adoptPtr(new NodeRareData(documentInternal()));
}
void Node::clearRareData()
diff --git a/Source/WebCore/dom/Node.h b/Source/WebCore/dom/Node.h
index 6593f78..5bdfbea 100644
--- a/Source/WebCore/dom/Node.h
+++ b/Source/WebCore/dom/Node.h
@@ -114,11 +114,19 @@
public:
RenderObject* renderer() const { return m_renderer; }
void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
+
+ TreeScope* treeScope() const { return m_treeScope; }
+ void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
+
virtual ~NodeRareDataBase() { }
protected:
- NodeRareDataBase() { }
+ NodeRareDataBase(TreeScope* scope)
+ : m_treeScope(scope)
+ {
+ }
private:
RenderObject* m_renderer;
+ TreeScope* m_treeScope;
};
class Node : public EventTarget, public ScriptWrappable, public TreeShared<Node, ContainerNode> {
@@ -770,8 +778,7 @@
void removedLastRef();
// These API should be only used for a tree scope migration.
- // setTreeScope() returns NodeRareData to save extra nodeRareData() invocations on the caller site.
- NodeRareData* setTreeScope(TreeScope*);
+ void setTreeScope(TreeScope*);
void setDocument(Document*);
enum EditableLevel { Editable, RichlyEditable };
diff --git a/Source/WebCore/dom/NodeRareData.cpp b/Source/WebCore/dom/NodeRareData.cpp
index 087f9c3..fdb8624 100644
--- a/Source/WebCore/dom/NodeRareData.cpp
+++ b/Source/WebCore/dom/NodeRareData.cpp
@@ -49,7 +49,7 @@
void NodeRareData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
{
MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
- info.addMember(m_treeScope);
+ info.addMember(treeScope());
info.addMember(m_nodeLists);
info.addMember(m_childNodeList);
diff --git a/Source/WebCore/dom/NodeRareData.h b/Source/WebCore/dom/NodeRareData.h
index ac551c3..f8f858c 100644
--- a/Source/WebCore/dom/NodeRareData.h
+++ b/Source/WebCore/dom/NodeRareData.h
@@ -199,8 +199,8 @@
class NodeRareData : public NodeRareDataBase {
WTF_MAKE_NONCOPYABLE(NodeRareData); WTF_MAKE_FAST_ALLOCATED;
public:
- NodeRareData()
- : m_treeScope(0)
+ NodeRareData(Document* document)
+ : NodeRareDataBase(document)
, m_childNodeList(0)
, m_tabIndex(0)
, m_childIndex(0)
@@ -230,9 +230,6 @@
{
}
- TreeScope* treeScope() const { return m_treeScope; }
- void setTreeScope(TreeScope* treeScope) { m_treeScope = treeScope; }
-
void clearNodeLists() { m_nodeLists.clear(); }
void setNodeLists(PassOwnPtr<NodeListsNodeData> lists) { m_nodeLists = lists; }
NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
@@ -366,7 +363,6 @@
void setChildIndex(unsigned index) { m_childIndex = index; }
private:
- TreeScope* m_treeScope;
OwnPtr<NodeListsNodeData> m_nodeLists;
ChildNodeList* m_childNodeList;
short m_tabIndex;
diff --git a/Source/WebCore/dom/TreeScopeAdopter.cpp b/Source/WebCore/dom/TreeScopeAdopter.cpp
index c775315..8cd6249 100644
--- a/Source/WebCore/dom/TreeScopeAdopter.cpp
+++ b/Source/WebCore/dom/TreeScopeAdopter.cpp
@@ -49,7 +49,9 @@
oldDocument->incDOMTreeVersion();
for (Node* node = root; node; node = node->traverseNextNode(root)) {
- if (NodeRareData* rareData = node->setTreeScope(newDocument == m_newScope ? 0 : m_newScope)) {
+ node->setTreeScope(m_newScope);
+ if (node->hasRareData()) {
+ NodeRareData* rareData = node->rareData();
if (rareData->nodeLists())
rareData->nodeLists()->adoptTreeScope(oldDocument, newDocument);
}