Reviewed by Chris and Darin.
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2004 01:34:11 +0000 (01:34 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Nov 2004 01:34:11 +0000 (01:34 +0000)
        <rdar://problem/3880304> Non-linear performance hit for style changes

        * khtml/xml/dom_nodeimpl.cpp:
        (NodeImpl::traverseNextNode):
        (NodeImpl::traverseNextSibling):
        (NodeImpl::traversePreviousNodePostOrder):
        Return 0 rather than traversing beyond stayWithin when this == stayWithin.
        Add asserts that stayWithin is an ancestor of the returned node.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8020 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/xml/dom_nodeimpl.cpp

index 5d6cce2..c7239d8 100644 (file)
@@ -1,3 +1,16 @@
+2004-11-15  David Harrison  <harrison@apple.com>
+
+        Reviewed by Chris and Darin.
+        
+        <rdar://problem/3880304> Non-linear performance hit for style changes
+
+        * khtml/xml/dom_nodeimpl.cpp:
+        (NodeImpl::traverseNextNode):
+        (NodeImpl::traverseNextSibling):
+        (NodeImpl::traversePreviousNodePostOrder):
+        Return 0 rather than traversing beyond stayWithin when this == stayWithin.
+        Add asserts that stayWithin is an ancestor of the returned node.
+
 2004-11-15  Darin Adler  <darin@apple.com>
 
         Reviewed by Ken.
index 9244e63..18e2e21 100644 (file)
@@ -940,27 +940,41 @@ NodeImpl *NodeImpl::childNode(unsigned long /*index*/)
 
 NodeImpl *NodeImpl::traverseNextNode(NodeImpl *stayWithin) const
 {
-    if (firstChild())
+    if (firstChild()) {
+        assert(!stayWithin || firstChild()->isAncestor(stayWithin));
        return firstChild();
-    if (nextSibling())
+    }
+    if (this == stayWithin)
+        return 0;
+    if (nextSibling()) {
+        assert(!stayWithin || nextSibling()->isAncestor(stayWithin));
        return nextSibling();
+    }
     const NodeImpl *n = this;
     while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))
         n = n->parentNode();
-    if (n)
+    if (n) {
+        assert(!stayWithin || !n->nextSibling() || n->nextSibling()->isAncestor(stayWithin));
         return n->nextSibling();
+    }
     return 0;
 }
 
 NodeImpl *NodeImpl::traverseNextSibling(NodeImpl *stayWithin) const
 {
-    if (nextSibling())
+    if (this == stayWithin)
+        return 0;
+    if (nextSibling()) {
+        assert(!stayWithin || nextSibling()->isAncestor(stayWithin));
        return nextSibling();
+    }
     const NodeImpl *n = this;
     while (n && !n->nextSibling() && (!stayWithin || n->parentNode() != stayWithin))
         n = n->parentNode();
-    if (n)
+    if (n) {
+        assert(!stayWithin || !n->nextSibling() || n->nextSibling()->isAncestor(stayWithin));
         return n->nextSibling();
+    }
     return 0;
 }
 
@@ -982,15 +996,23 @@ NodeImpl *NodeImpl::traversePreviousNode() const
 
 NodeImpl *NodeImpl::traversePreviousNodePostOrder(NodeImpl *stayWithin) const
 {
-    if (lastChild())
+    if (lastChild()) {
+        assert(!stayWithin || lastChild()->isAncestor(stayWithin));
        return lastChild();
-    if (previousSibling())
+    }
+    if (this == stayWithin)
+        return 0;
+    if (previousSibling()) {
+        assert(!stayWithin || previousSibling()->isAncestor(stayWithin));
        return previousSibling();
+    }
     const NodeImpl *n = this;
     while (n && !n->previousSibling() && (!stayWithin || n->parentNode() != stayWithin))
         n = n->parentNode();
-    if (n)
+    if (n) {
+        assert(!stayWithin || !n->previousSibling() || n->previousSibling()->isAncestor(stayWithin));
         return n->previousSibling();
+    }
     return 0;
 }