Changeset 84701 in webkit


Ignore:
Timestamp:
Apr 22, 2011 4:11:45 PM (13 years ago)
Author:
msaboff@apple.com
Message:

2011-04-22 Michael Saboff <msaboff@apple.com>

Reviewed by Maciej Stachowiak.

Creating copy of ContainerNode's when inserting or removing is inefficient
https://bugs.webkit.org/show_bug.cgi?id=58695

Eliminated node copying in willRemove() and insertedIntoDocument().

No new tests as this is a more efficient implementation of
existing code that is covered by existing tests.

  • dom/ContainerNode.cpp: (WebCore::ContainerNode::willRemove): Changed method to use RefPtr<> to protect against modification during removal. (WebCore::ContainerNode::insertedIntoDocument): Changed method to use RefPtr<> and two other deletion checks to protect against modification during insertion.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84699 r84701  
     12011-04-22  Michael Saboff  <msaboff@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Creating copy of ContainerNode's when inserting or removing is inefficient
     6        https://bugs.webkit.org/show_bug.cgi?id=58695
     7
     8        Eliminated node copying in willRemove() and insertedIntoDocument().
     9
     10        No new tests as this is a more efficient implementation of
     11        existing code that is covered by existing tests.
     12
     13        * dom/ContainerNode.cpp:
     14        (WebCore::ContainerNode::willRemove): Changed method to use
     15        RefPtr<> to protect against modification during removal.
     16        (WebCore::ContainerNode::insertedIntoDocument): Changed method to use
     17        RefPtr<> and two other deletion checks to protect against
     18        modification during insertion.
     19
    1202011-04-22  Geoffrey Garen  <ggaren@apple.com>
    221
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r84394 r84701  
    367367void ContainerNode::willRemove()
    368368{
    369     Vector<RefPtr<Node>, 10> nodes;
    370     nodes.reserveInitialCapacity(childNodeCount());
    371     for (Node* n = m_lastChild; n; n = n->previousSibling())
    372         nodes.append(n);
    373     for (; nodes.size(); nodes.removeLast())
    374         nodes.last().get()->willRemove();
     369    RefPtr<Node> protect(this);
     370
     371    for (RefPtr<Node> child = firstChild(); child; child = child->nextSibling()) {
     372        if (child->parentNode() != this) // Check for child being removed from subtree while removing.
     373            break;
     374        child->willRemove();
     375    }
    375376    Node::willRemove();
    376377}
     
    746747void ContainerNode::insertedIntoDocument()
    747748{
     749    RefPtr<Node> protect(this);
     750
    748751    Node::insertedIntoDocument();
    749752    insertedIntoTree(false);
    750753
    751     // Determine set of children before operating on any of them.
    752     NodeVector children;
    753     collectNodes(this, children);
    754 
    755     NodeVector::iterator it;
    756     for (it = children.begin(); it != children.end() && inDocument(); ++it) {
    757         Node* child = it->get();
     754    for (RefPtr<Node> child = m_firstChild; child; child = child->nextSibling()) {
     755        // Guard against mutation during re-parenting.
     756        if (!inDocument()) // Check for self being removed from document while reparenting.
     757            break;
     758        if (child->parentNode() != this) // Check for child being removed from subtree while reparenting.
     759            break;
    758760        child->insertedIntoDocument();
    759761    }
Note: See TracChangeset for help on using the changeset viewer.