Title: [101967] trunk/Source/WebCore
- Revision
- 101967
- Author
- [email protected]
- Date
- 2011-12-04 13:52:56 -0800 (Sun, 04 Dec 2011)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (101966 => 101967)
--- trunk/Source/WebCore/ChangeLog 2011-12-04 21:50:37 UTC (rev 101966)
+++ trunk/Source/WebCore/ChangeLog 2011-12-04 21:52:56 UTC (rev 101967)
@@ -1,3 +1,24 @@
+2011-12-04 Ryosuke Niwa <[email protected]>
+
+ 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):
+
2011-12-04 Andreas Kling <[email protected]>
CSSValuePool: Inline trivial getters.
Modified: trunk/Source/WebCore/dom/Node.cpp (101966 => 101967)
--- trunk/Source/WebCore/dom/Node.cpp 2011-12-04 21:50:37 UTC (rev 101966)
+++ trunk/Source/WebCore/dom/Node.cpp 2011-12-04 21:52:56 UTC (rev 101967)
@@ -1348,8 +1348,10 @@
bool Node::isDescendantOf(const Node *other) const
{
// Return true if other is an ancestor of this, otherwise false
- if (!other)
+ if (!other || !other->firstChild() || inDocument() != other->inDocument())
return false;
+ if (other == other->document())
+ return document() == other && this != document() && inDocument();
for (const ContainerNode* n = parentNode(); n; n = n->parentNode()) {
if (n == other)
return true;
@@ -1361,8 +1363,6 @@
{
if (!node)
return false;
- if (document() == this)
- return node->document() == this && node->inDocument();
return this == node || node->isDescendantOf(this);
}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes