[Refactoring] Replace Node's Document pointer with a TreeScope pointer
authormorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2012 06:33:48 +0000 (06:33 +0000)
committermorrita@google.com <morrita@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jul 2012 06:33:48 +0000 (06:33 +0000)
commitd275c39eed0c00a4835bd11c0c42800ae8e7e03d
treed3636b5f6d1d7058132438e3430b1c46618aa947
parentf5b35910f101f218a816097a7823cea4f3e0f7b0
[Refactoring] Replace Node's Document pointer with a TreeScope pointer
https://bugs.webkit.org/show_bug.cgi?id=59816

Reviewed by Ryosuke Niwa.

.:

* Source/autotools/symbols.filter: Added newly exported symbols.

Source/WebCore:

Before this change, Node::treeScope() fetches the TreeScope object
from ElementRareData. This approach has several shortcomings:

- rareData() call is slow due to a hashtable lookup.
- In shadow tree, each node has its tree scope in ElementRareData,
  that means the rare-data is no longer rare in that case.

This change gets rid of ElementRareData::m_treeScope by replacing
Node::m_document with Node::m_treeScope. And retrieves the
document of Node through m_treeScope.

Note that Node::document() is a hot function and naive
replacemennt of m_document with m_treeScope can hurt the
speed. This change employs some tricks to address it.

- This change introduces Node::InShadowTree flag, if the flag is off,
  that means m_treeScope is actually a document an can be returned as the result.
  this eliminates an extract dereference.
- Node::m_treeScope can be null. But we don't want to issue any extra
  conditional statement. So this change represents a null
  TreeScope as TreeScope::nullInstance(), which saves one conditional
  statement.

With these changes, the Node::document() slowdown is minimized to
unnoticeable size.

No new tests. Covered by existing tests.

* dom/Document.cpp: Took care of connectio betwen TreeScope.
(WebCore::Document::Document):
(WebCore::Document::~Document):
(WebCore::Document::suggestedMIMEType):
* dom/Document.h:
(WebCore::Node::treeScope): Now just return m_treeScope, taking care of nullInstance() case.
(WebCore):
(WebCore::Node::setTreeScope): Now just sets m_treeScope.
(WebCore::Node::documentInternal): Extracted from document() to have ASSERT-free version.
(WebCore::Node::document): Re-implemented over treeScope() and the flag.
(WebCore::Node::isDocumentNode): Re-implemented using treeScope()
(WebCore::Node::Node):
* dom/Node.cpp:
(WebCore::Node::~Node):
(WebCore::Node::reportMemoryUsage):
* dom/Node.h:
(Node):
(WebCore::Node::inDocument):
(WebCore::Node::isInShadowTree): Rewrote to use InShadowTree flag.
* dom/NodeRareData.h:
(WebCore::NodeRareData::NodeRareData): Eliminated m_treeScope.
(NodeRareData):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::ShadowRoot):
* dom/TreeScope.cpp:
(WebCore::TreeScope::TreeScope):
(WebCore):
(WebCore::TreeScope::setParentTreeScope): Added.
(WebCore::TreeScope::isDocumentScope): Added.
(WebCore::TreeScope::nullInstance): Added.
* dom/TreeScope.h: Added m_parentTreeScope.
(WebCore):
(WebCore::TreeScope::rootDocument): Added.
(TreeScope):
* dom/TreeScopeAdopter.cpp: No longer calls setDocument()
(WebCore::TreeScopeAdopter::moveTreeToNewScope):
(WebCore::TreeScopeAdopter::moveNodeToNewDocument):
* editing/MoveSelectionCommand.cpp: Includes Document.h to find inlined Node functions
* editing/RemoveNodeCommand.cpp: Includes Document.h to find inlined Node functions
* editing/RemoveNodePreservingChildrenCommand.cpp: Includes Document.h to find inlined Node functions
* inspector/PageConsoleAgent.cpp: Includes Document.h to find inlined Node functions

Source/WebKit2:

* win/WebKit2.def: Added newly exported symbols.
* win/WebKit2CFLite.def: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@123184 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/NodeRareData.h
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/dom/TreeScope.h
Source/WebCore/dom/TreeScopeAdopter.cpp
Source/WebCore/editing/MoveSelectionCommand.cpp
Source/WebCore/editing/RemoveNodeCommand.cpp
Source/WebCore/editing/RemoveNodePreservingChildrenCommand.cpp
Source/WebCore/inspector/PageConsoleAgent.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def
Source/WebKit2/win/WebKit2CFLite.def
Source/autotools/symbols.filter