Changeset 84701 in webkit
- Timestamp:
- Apr 22, 2011 4:11:45 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r84699 r84701 1 2011-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 1 20 2011-04-22 Geoffrey Garen <ggaren@apple.com> 2 21 -
trunk/Source/WebCore/dom/ContainerNode.cpp
r84394 r84701 367 367 void ContainerNode::willRemove() 368 368 { 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 } 375 376 Node::willRemove(); 376 377 } … … 746 747 void ContainerNode::insertedIntoDocument() 747 748 { 749 RefPtr<Node> protect(this); 750 748 751 Node::insertedIntoDocument(); 749 752 insertedIntoTree(false); 750 753 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; 758 760 child->insertedIntoDocument(); 759 761 }
Note: See TracChangeset
for help on using the changeset viewer.