Changeset 116677 in webkit


Ignore:
Timestamp:
May 10, 2012 12:52:05 PM (12 years ago)
Author:
Antti Koivisto
Message:

Inline Node::traverseNextNode
https://bugs.webkit.org/show_bug.cgi?id=85844

Reviewed by Ryosuke Niwa.

Inline traverseNextNode and traverseNextSibling to reduce entry/exit overhead and allow better code generation
for many hot loops.

In this version only the firstChild()/nextSibling() tests are inlined and the ancestor traversal is not.

Performance bots will tell if this was worthwhile.

  • dom/ContainerNode.h:

(WebCore::Node::traverseNextNode):
(WebCore):
(WebCore::Node::traverseNextSibling):

  • dom/Node.cpp:

(WebCore::Node::traverseNextAncestorSibling):

  • dom/Node.h:

(Node):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116675 r116677  
     12012-05-10  Antti Koivisto  <antti@apple.com>
     2
     3        Inline Node::traverseNextNode
     4        https://bugs.webkit.org/show_bug.cgi?id=85844
     5
     6        Reviewed by Ryosuke Niwa.
     7       
     8        Inline traverseNextNode and traverseNextSibling to reduce entry/exit overhead and allow better code generation
     9        for many hot loops.
     10
     11        In this version only the firstChild()/nextSibling() tests are inlined and the ancestor traversal is not.
     12       
     13        Performance bots will tell if this was worthwhile.
     14
     15        * dom/ContainerNode.h:
     16        (WebCore::Node::traverseNextNode):
     17        (WebCore):
     18        (WebCore::Node::traverseNextSibling):
     19        * dom/Node.cpp:
     20        (WebCore::Node::traverseNextAncestorSibling):
     21        * dom/Node.h:
     22        (Node):
     23
    1242012-05-10  Tommy Widenflycht  <tommyw@google.com>
    225
  • trunk/Source/WebCore/WebCore.exp.in

    r116549 r116677  
    21002100__ZN7WebCore8Document22setAnimatingFullScreenEb
    21012101__ZNK7WebCore8Document9domWindowEv
    2102 __ZNK7WebCore4Node16traverseNextNodeEPKS0_
     2102__ZNK7WebCore4Node27traverseNextAncestorSiblingEv
    21032103#endif
    21042104
  • trunk/Source/WebCore/dom/ContainerNode.h

    r116629 r116677  
    230230}
    231231
     232inline Node* Node::traverseNextSibling() const
     233{
     234    if (nextSibling())
     235        return nextSibling();
     236    return traverseNextAncestorSibling();
     237}
     238
     239inline Node* Node::traverseNextNode() const
     240{
     241    if (firstChild())
     242        return firstChild();
     243    return traverseNextSibling();
     244}
     245
     246inline Node* Node::traverseNextSibling(const Node* stayWithin) const
     247{
     248    if (this == stayWithin)
     249        return 0;
     250    if (nextSibling())
     251        return nextSibling();
     252    return traverseNextAncestorSibling(stayWithin);
     253}
     254
     255inline Node* Node::traverseNextNode(const Node* stayWithin) const
     256{
     257    if (firstChild())
     258        return firstChild();
     259    return traverseNextSibling(stayWithin);
     260}
     261
    232262typedef Vector<RefPtr<Node>, 11> NodeVector;
    233263
  • trunk/Source/WebCore/dom/Node.cpp

    r116644 r116677  
    10891089}
    10901090
    1091 Node* Node::traverseNextNode(const Node* stayWithin) const
    1092 {
    1093     if (firstChild())
    1094         return firstChild();
    1095     if (this == stayWithin)
    1096         return 0;
    1097     if (nextSibling())
    1098         return nextSibling();
    1099     const Node *n = this;
    1100     while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))
    1101         n = n->parentNode();
    1102     if (n)
    1103         return n->nextSibling();
     1091Node* Node::traverseNextAncestorSibling() const
     1092{
     1093    ASSERT(!nextSibling());
     1094    for (const Node* node = parentNode(); node; node = node->parentNode()) {
     1095        if (node->nextSibling())
     1096            return node->nextSibling();
     1097    }
    11041098    return 0;
    11051099}
    11061100
    1107 Node* Node::traverseNextSibling(const Node* stayWithin) const
    1108 {
    1109     if (this == stayWithin)
    1110         return 0;
    1111     if (nextSibling())
    1112         return nextSibling();
    1113     const Node *n = this;
    1114     while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))
    1115         n = n->parentNode();
    1116     if (n)
    1117         return n->nextSibling();
     1101Node* Node::traverseNextAncestorSibling(const Node* stayWithin) const
     1102{
     1103    ASSERT(!nextSibling());
     1104    ASSERT(this != stayWithin);
     1105    for (const Node* node = parentNode(); node; node = node->parentNode()) {
     1106        if (node == stayWithin)
     1107            return 0;
     1108        if (node->nextSibling())
     1109            return node->nextSibling();
     1110    }
    11181111    return 0;
    11191112}
  • trunk/Source/WebCore/dom/Node.h

    r116644 r116677  
    432432    // argument is non-null, the traversal will stop once the specified node is reached.
    433433    // This can be used to restrict traversal to a particular sub-tree.
    434     Node* traverseNextNode(const Node* stayWithin = 0) const;
     434    Node* traverseNextNode() const;
     435    Node* traverseNextNode(const Node* stayWithin) const;
    435436
    436437    // Like traverseNextNode, but skips children and starts with the next sibling.
    437     Node* traverseNextSibling(const Node* stayWithin = 0) const;
     438    Node* traverseNextSibling() const;
     439    Node* traverseNextSibling(const Node* stayWithin) const;
    438440
    439441    // Does a reverse pre-order traversal to find the node that comes before the current one in document order
     
    768770    Element* ancestorElement() const;
    769771
     772    Node* traverseNextAncestorSibling() const;
     773    Node* traverseNextAncestorSibling(const Node* stayWithin) const;
     774
    770775    // Use Node::parentNode as the consistent way of querying a parent node.
    771776    // This method is made private to ensure a compiler error on call sites that
Note: See TracChangeset for help on using the changeset viewer.