Changeset 101967 in webkit


Ignore:
Timestamp:
Dec 4, 2011 1:52:56 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

HIERARCHY_REQUEST_ERR check in checkAcceptChild should be optimized for newChild without children
https://bugs.webkit.org/show_bug.cgi?id=73737

Reviewed by Darin Adler.

It turned out that 50-70% of nodes inserted by DOM APIs such as insertBefore and appendChild
don't have any descendent nodes. Optimize isDescendantOf which is used by checkAcceptChild for this case.
On a test case attached on the bug, we see a 40% improvement.

Also optimize for cases where either new child or new parent but not both are in document as suggested
by Erik Arvidsson. This appears to happen about 40-70% of the time, and the symmetric difference between
the two cases is about 50% so it's worth implementing both optimizations.

Unfortunately no tests because we still have a O(n) algorithm somewhere.

  • dom/Node.cpp:

(WebCore::Node::isDescendantOf):
(WebCore::Node::contains):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r101959 r101967  
     12011-12-04  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        HIERARCHY_REQUEST_ERR check in checkAcceptChild should be optimized for newChild without children
     4        https://bugs.webkit.org/show_bug.cgi?id=73737
     5
     6        Reviewed by Darin Adler.
     7
     8        It turned out that 50-70% of nodes inserted by DOM APIs such as insertBefore and appendChild
     9        don't have any descendent nodes. Optimize isDescendantOf which is used by checkAcceptChild for this case.
     10        On a test case attached on the bug, we see a 40% improvement.
     11
     12        Also optimize for cases where either new child or new parent but not both are in document as suggested
     13        by Erik Arvidsson. This appears to happen about 40-70% of the time, and the symmetric difference between
     14        the two cases is about 50% so it's worth implementing both optimizations.
     15
     16        Unfortunately no tests because we still have a O(n) algorithm somewhere.
     17
     18        * dom/Node.cpp:
     19        (WebCore::Node::isDescendantOf):
     20        (WebCore::Node::contains):
     21
    1222011-12-04  Andreas Kling  <kling@webkit.org>
    223
  • trunk/Source/WebCore/dom/Node.cpp

    r101144 r101967  
    13491349{
    13501350    // Return true if other is an ancestor of this, otherwise false
    1351     if (!other)
    1352         return false;
     1351    if (!other || !other->firstChild() || inDocument() != other->inDocument())
     1352        return false;
     1353    if (other == other->document())
     1354        return document() == other && this != document() && inDocument();
    13531355    for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) {
    13541356        if (n == other)
     
    13621364    if (!node)
    13631365        return false;
    1364     if (document() == this)
    1365         return node->document() == this && node->inDocument();
    13661366    return this == node || node->isDescendantOf(this);
    13671367}
Note: See TracChangeset for help on using the changeset viewer.