Bug 944149 , Optimize ComparePosition, r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 28 Nov 2013 14:07:43 +0200
changeset 157887 bf413fe5f44e372d68959f943b3a1ce70ea0c233
parent 157886 dd032c97a9a84559ae7dacb564eea13e4f63673b
child 157888 026aec496a073f74199e79c48b353cb86e6c6fca
push id36885
push useropettay@mozilla.com
push dateThu, 28 Nov 2013 12:17:37 +0000
treeherdermozilla-inbound@026aec496a07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs944149
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 944149 , Optimize ComparePosition, r=bz
content/base/src/nsINode.cpp
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -734,16 +734,24 @@ nsINode::GetUserData(JSContext* aCx, con
 }
 
 uint16_t
 nsINode::CompareDocumentPosition(nsINode& aOtherNode) const
 {
   if (this == &aOtherNode) {
     return 0;
   }
+  if (GetPreviousSibling() == &aOtherNode) {
+    MOZ_ASSERT(GetParentNode() == aOtherNode.GetParentNode());
+    return static_cast<uint16_t>(nsIDOMNode::DOCUMENT_POSITION_PRECEDING);
+  }
+  if (GetNextSibling() == &aOtherNode) {
+    MOZ_ASSERT(GetParentNode() == aOtherNode.GetParentNode());
+    return static_cast<uint16_t>(nsIDOMNode::DOCUMENT_POSITION_FOLLOWING);
+  }
 
   nsAutoTArray<const nsINode*, 32> parents1, parents2;
 
   const nsINode *node1 = &aOtherNode, *node2 = this;
 
   // Check if either node is an attribute
   const nsIAttribute* attr1 = nullptr;
   if (node1->IsNodeOfType(nsINode::eATTRIBUTE)) {