insertedIntoDocument and insertedIntoTree should be unitifed.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2012 06:40:55 +0000 (06:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2012 06:40:55 +0000 (06:40 +0000)
commit55a3d476da08ee949f19e453f9472c23a0971ca3
tree1700f94384b45146c1eeb3f75ad420ed62f5722c
parentad7ad684fddb2dcdd7a5b5426530f88f3ab5ecd5
insertedIntoDocument and insertedIntoTree should be unitifed.
https://bugs.webkit.org/show_bug.cgi?id=82701

Patch by Hajime Morrita <morrita@chromium.org> on 2012-04-16
Reviewed by Ryosuke Niwa.

Both Node::insertedIntoTree() and Node::insertedIntoDocument() are
served as lifecycle callbacks which are invoked when a node is
inserted into its new parent. There are also removedFromTree()
and removedFromDocument() respectively. Considering that this pair
of virtual functions are laid onto the hot path, it's worth
merging them into one, to gain some speedup. Such
unification could clarify the semantics as well.

This change makes following change to merge these functions.

- pulling the tree traversal out from ContainerNode to ChildNodeInsertionNotifier.
- letting new Node::insertInto() do the job for its own, but not
  for its children and
- Pass the parent of each insertion root as a parameter of insertedInto().
  This root node can tell inserted node where it is inserted,
  specifically whetehr the insertion is to the document or not.

Same pattern is also applied to Node::removedFromDocument() and
Node::removedFromTree(), which are factored to Node::removedFrom()
and ChildNodeRemovalNotifier respectively.

Speed up on Dromaeo/dom-modify.html is about 2%.
Further speed-up by de-virtulization would be possible.

Caveat:

There is possible situation where a node need to invoke
insertedInto() after its children is nofitied, instead of before
that.  It was represented naturally with previous
traversal-by-ContainerNode pattern, but is no longer simple with
this new external traversal. To support this scenario, we
introduced the InsertionNotificationRequest as a return value of insertedInto()
and a supplemental hook Node::didNotifyDescendantInseretions(). See for
example HTMLFormElement.cpp to learn how it works.

No new tests. Covered by existing tests.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.xcodeproj/project.pbxproj:
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::parserInsertBefore):
(WebCore::ContainerNode::removeChild):
(WebCore::ContainerNode::parserRemoveChild):
(WebCore::ContainerNode::removeChildren):
(WebCore::ContainerNode::parserAddChild):
(WebCore::updateTreeAfterInsertion):
* dom/ContainerNode.h:
(ContainerNode):
(WebCore::Node::highestAncestor):
(WebCore):
* dom/ContainerNodeAlgorithms.cpp: Added.
(WebCore):
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
(WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromDocument):
(WebCore::ChildNodeRemovalNotifier::notifyDescendantRemovedFromTree):
* dom/ContainerNodeAlgorithms.h:
(ChildNodeInsertionNotifier):
(WebCore::ChildNodeInsertionNotifier::ChildNodeInsertionNotifier):
(WebCore):
(ChildNodeRemovalNotifier):
(WebCore::ChildNodeRemovalNotifier::ChildNodeRemovalNotifier):
(WebCore::removeAllChildrenInContainer):
(WebCore::appendChildToContainer):
(Private):
(WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument):
(WebCore::ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree):
(WebCore::ChildNodeInsertionNotifier::notifyInsertedIntoDocument):
(WebCore::ChildNodeInsertionNotifier::notify):
(WebCore::ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument):
(WebCore::ChildNodeRemovalNotifier::notifyNodeRemovedFromTree):
(WebCore::ChildNodeRemovalNotifier::notify):
* dom/DOMAllInOne.cpp:
* dom/DocumentType.cpp:
(WebCore::DocumentType::insertedInto):
(WebCore::DocumentType::removedFrom):
* dom/DocumentType.h:
(DocumentType):
* dom/Element.cpp:
(WebCore::Element::insertedInto):
(WebCore::Element::removedFrom):
* dom/Element.h:
(Element):
* dom/Node.cpp:
(WebCore::Node::insertedInto):
(WebCore::Node::removedFrom):
* dom/Node.h:
(Node):
(WebCore::Node::didNotifyDescendantInseretions):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::insertedInto):
(WebCore::ProcessingInstruction::removedFrom):
* dom/ProcessingInstruction.h:
(ProcessingInstruction):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::insertedInto):
* dom/ScriptElement.h:
(WebCore):
(ScriptElement):
* dom/ShadowTree.cpp:
(WebCore::ShadowTree::addShadowRoot):
(WebCore::ShadowTree::removeAllShadowRoots):
* dom/ShadowTree.h:
(ShadowTree):
(ShadowRootVector):
(WebCore::ShadowRootVector::ShadowRootVector):
(WebCore):
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::insertedInto):
(WebCore::FormAssociatedElement::removedFrom):
(WebCore::FormAssociatedElement::formRemovedFromTree):
* html/FormAssociatedElement.h:
(FormAssociatedElement):
* html/HTMLBaseElement.cpp:
(WebCore::HTMLBaseElement::insertedInto):
(WebCore::HTMLBaseElement::removedFrom):
* html/HTMLBaseElement.h:
(HTMLBaseElement):
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::insertedInto):
(WebCore::HTMLBodyElement::didNotifyDescendantInseretions):
* html/HTMLBodyElement.h:
(HTMLBodyElement):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::insertedInto):
(WebCore::HTMLFormControlElement::removedFrom):
* html/HTMLFormControlElement.h:
(HTMLFormControlElement):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::insertedInto):
(WebCore::HTMLFormElement::didNotifyDescendantInseretions):
(WebCore::HTMLFormElement::removedFrom):
* html/HTMLFormElement.h:
(HTMLFormElement):
* html/HTMLFrameElementBase.cpp:
(WebCore::HTMLFrameElementBase::insertedInto):
(WebCore):
(WebCore::HTMLFrameElementBase::didNotifyDescendantInseretions):
* html/HTMLFrameElementBase.h:
(HTMLFrameElementBase):
* html/HTMLFrameSetElement.cpp:
(WebCore::HTMLFrameSetElement::insertedInto):
(WebCore::HTMLFrameSetElement::removedFrom):
* html/HTMLFrameSetElement.h:
(HTMLFrameSetElement):
* html/HTMLIFrameElement.cpp:
(WebCore::HTMLIFrameElement::insertedInto):
(WebCore::HTMLIFrameElement::removedFrom):
* html/HTMLIFrameElement.h:
(HTMLIFrameElement):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::insertedInto):
(WebCore::HTMLImageElement::removedFrom):
* html/HTMLImageElement.h:
(HTMLImageElement):
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::insertedInto):
(WebCore::HTMLInputElement::removedFrom):
* html/HTMLInputElement.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::insertedInto):
(WebCore::HTMLLinkElement::removedFrom):
* html/HTMLLinkElement.h:
(HTMLLinkElement):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::insertedInto):
(WebCore::HTMLMapElement::removedFrom):
* html/HTMLMapElement.h:
(HTMLMapElement):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::insertedInto):
(WebCore::HTMLMediaElement::removedFrom):
* html/HTMLMediaElement.h:
(HTMLMediaElement):
* html/HTMLMetaElement.cpp:
(WebCore::HTMLMetaElement::insertedInto):
* html/HTMLMetaElement.h:
(HTMLMetaElement):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::insertedInto):
(WebCore::HTMLObjectElement::removedFrom):
* html/HTMLObjectElement.h:
(HTMLObjectElement):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::insertedInto):
* html/HTMLOptionElement.h:
(HTMLOptionElement):
* html/HTMLQuoteElement.cpp:
(WebCore::HTMLQuoteElement::insertedInto):
* html/HTMLQuoteElement.h:
(HTMLQuoteElement):
* html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::insertedInto):
* html/HTMLScriptElement.h:
(HTMLScriptElement):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::insertedInto):
* html/HTMLSelectElement.h:
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::insertedInto):
* html/HTMLSourceElement.h:
(HTMLSourceElement):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::insertedInto):
(WebCore::HTMLStyleElement::removedFrom):
* html/HTMLStyleElement.h:
(HTMLStyleElement):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::insertedInto):
* html/HTMLTextFormControlElement.h:
* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::insertedInto):
(WebCore::HTMLTitleElement::removedFrom):
* html/HTMLTitleElement.h:
(HTMLTitleElement):
* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::insertedInto):
* html/HTMLTrackElement.h:
(HTMLTrackElement):
* mathml/MathMLMathElement.cpp:
(WebCore::MathMLMathElement::insertedInto):
* mathml/MathMLMathElement.h:
(MathMLMathElement):
* svg/SVGElement.cpp:
(WebCore::SVGElement::removedFrom):
* svg/SVGElement.h:
(SVGElement):
* svg/SVGFEImageElement.cpp:
(WebCore::SVGFEImageElement::insertedInto):
(WebCore::SVGFEImageElement::removedFrom):
* svg/SVGFEImageElement.h:
(SVGFEImageElement):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::insertedInto):
(WebCore::SVGFontFaceElement::removedFrom):
* svg/SVGFontFaceElement.h:
(SVGFontFaceElement):
* svg/SVGFontFaceUriElement.cpp:
(WebCore::SVGFontFaceUriElement::insertedInto):
* svg/SVGFontFaceUriElement.h:
(SVGFontFaceUriElement):
* svg/SVGGlyphElement.cpp:
(WebCore::SVGGlyphElement::insertedInto):
(WebCore::SVGGlyphElement::removedFrom):
* svg/SVGGlyphElement.h:
(SVGGlyphElement):
* svg/SVGHKernElement.cpp:
(WebCore::SVGHKernElement::insertedInto):
(WebCore::SVGHKernElement::removedFrom):
* svg/SVGHKernElement.h:
(SVGHKernElement):
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::insertedInto):
* svg/SVGImageElement.h:
(SVGImageElement):
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::insertedInto):
(WebCore::SVGSVGElement::removedFrom):
* svg/SVGSVGElement.h:
(SVGSVGElement):
* svg/SVGScriptElement.cpp:
(WebCore::SVGScriptElement::insertedInto):
* svg/SVGScriptElement.h:
(SVGScriptElement):
* svg/SVGStyleElement.cpp:
(WebCore::SVGStyleElement::insertedInto):
(WebCore::SVGStyleElement::removedFrom):
* svg/SVGStyleElement.h:
(SVGStyleElement):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::insertedInto):
(WebCore::SVGStyledElement::removedFrom):
(WebCore::SVGStyledElement::updateRelativeLengthsInformation):
* svg/SVGStyledElement.h:
(SVGStyledElement):
* svg/SVGTRefElement.cpp:
(WebCore::SVGTRefElement::buildPendingResource):
(WebCore::SVGTRefElement::insertedInto):
(WebCore::SVGTRefElement::removedFrom):
* svg/SVGTRefElement.h:
(SVGTRefElement):
* svg/SVGTextPathElement.cpp:
(WebCore::SVGTextPathElement::insertedInto):
* svg/SVGTextPathElement.h:
* svg/SVGTitleElement.cpp:
(WebCore::SVGTitleElement::insertedInto):
(WebCore::SVGTitleElement::removedFrom):
* svg/SVGTitleElement.h:
(SVGTitleElement):
* svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::insertedInto):
(WebCore::SVGUseElement::removedFrom):
* svg/SVGUseElement.h:
(SVGUseElement):
* svg/SVGVKernElement.cpp:
(WebCore::SVGVKernElement::insertedInto):
(WebCore::SVGVKernElement::removedFrom):
* svg/SVGVKernElement.h:
(SVGVKernElement):
* svg/animation/SVGSMILElement.cpp:
(WebCore::SVGSMILElement::insertedInto):
(WebCore::SVGSMILElement::removedFrom):
* svg/animation/SVGSMILElement.h:
(SVGSMILElement):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@114351 268f45cc-cd09-0410-ab3c-d52691b4dbfc
107 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/ContainerNode.h
Source/WebCore/dom/ContainerNodeAlgorithms.cpp [new file with mode: 0644]
Source/WebCore/dom/ContainerNodeAlgorithms.h
Source/WebCore/dom/DOMAllInOne.cpp
Source/WebCore/dom/DocumentType.cpp
Source/WebCore/dom/DocumentType.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/dom/ProcessingInstruction.h
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/ScriptElement.h
Source/WebCore/dom/ShadowTree.cpp
Source/WebCore/dom/ShadowTree.h
Source/WebCore/html/FormAssociatedElement.cpp
Source/WebCore/html/FormAssociatedElement.h
Source/WebCore/html/HTMLBaseElement.cpp
Source/WebCore/html/HTMLBaseElement.h
Source/WebCore/html/HTMLBodyElement.cpp
Source/WebCore/html/HTMLBodyElement.h
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLFrameElementBase.cpp
Source/WebCore/html/HTMLFrameElementBase.h
Source/WebCore/html/HTMLFrameSetElement.cpp
Source/WebCore/html/HTMLFrameSetElement.h
Source/WebCore/html/HTMLIFrameElement.cpp
Source/WebCore/html/HTMLIFrameElement.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/HTMLMapElement.cpp
Source/WebCore/html/HTMLMapElement.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMetaElement.cpp
Source/WebCore/html/HTMLMetaElement.h
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/HTMLObjectElement.h
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLOptionElement.h
Source/WebCore/html/HTMLQuoteElement.cpp
Source/WebCore/html/HTMLQuoteElement.h
Source/WebCore/html/HTMLScriptElement.cpp
Source/WebCore/html/HTMLScriptElement.h
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElement.h
Source/WebCore/html/HTMLSourceElement.cpp
Source/WebCore/html/HTMLSourceElement.h
Source/WebCore/html/HTMLStyleElement.cpp
Source/WebCore/html/HTMLStyleElement.h
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h
Source/WebCore/html/HTMLTitleElement.cpp
Source/WebCore/html/HTMLTitleElement.h
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/mathml/MathMLMathElement.cpp
Source/WebCore/mathml/MathMLMathElement.h
Source/WebCore/svg/SVGElement.cpp
Source/WebCore/svg/SVGElement.h
Source/WebCore/svg/SVGFEImageElement.cpp
Source/WebCore/svg/SVGFEImageElement.h
Source/WebCore/svg/SVGFontFaceElement.cpp
Source/WebCore/svg/SVGFontFaceElement.h
Source/WebCore/svg/SVGFontFaceUriElement.cpp
Source/WebCore/svg/SVGFontFaceUriElement.h
Source/WebCore/svg/SVGGlyphElement.cpp
Source/WebCore/svg/SVGGlyphElement.h
Source/WebCore/svg/SVGHKernElement.cpp
Source/WebCore/svg/SVGHKernElement.h
Source/WebCore/svg/SVGImageElement.cpp
Source/WebCore/svg/SVGImageElement.h
Source/WebCore/svg/SVGSVGElement.cpp
Source/WebCore/svg/SVGSVGElement.h
Source/WebCore/svg/SVGScriptElement.cpp
Source/WebCore/svg/SVGScriptElement.h
Source/WebCore/svg/SVGStyleElement.cpp
Source/WebCore/svg/SVGStyleElement.h
Source/WebCore/svg/SVGStyledElement.cpp
Source/WebCore/svg/SVGStyledElement.h
Source/WebCore/svg/SVGTRefElement.cpp
Source/WebCore/svg/SVGTRefElement.h
Source/WebCore/svg/SVGTextPathElement.cpp
Source/WebCore/svg/SVGTextPathElement.h
Source/WebCore/svg/SVGTitleElement.cpp
Source/WebCore/svg/SVGTitleElement.h
Source/WebCore/svg/SVGUseElement.cpp
Source/WebCore/svg/SVGUseElement.h
Source/WebCore/svg/SVGVKernElement.cpp
Source/WebCore/svg/SVGVKernElement.h
Source/WebCore/svg/animation/SVGSMILElement.cpp
Source/WebCore/svg/animation/SVGSMILElement.h