Bug 1001562 - Make SetXBLInsertionParent(nullptr) and SetXBLBinding(nullptr, ...) lazier. r=smaug
authorAndrew McCreight <continuation@gmail.com>
Mon, 28 Apr 2014 06:15:08 -0700
changeset 180939 c259840960975b62b1f74cd58b3327b876ef5aef
parent 180938 a249af412db860e49a25fd0c4e98939c69a4b0f9
child 180940 932f6530318dda3eec3310596658de18867c6d03
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerssmaug
bugs1001562
milestone31.0a1
Bug 1001562 - Make SetXBLInsertionParent(nullptr) and SetXBLBinding(nullptr, ...) lazier. r=smaug
content/base/src/FragmentOrElement.cpp
content/base/src/nsGenericDOMDataNode.cpp
--- a/content/base/src/FragmentOrElement.cpp
+++ b/content/base/src/FragmentOrElement.cpp
@@ -949,23 +949,26 @@ FragmentOrElement::SetXBLBinding(nsXBLBi
   // constructor twice (if aBinding inherits from it) or firing its constructor
   // after aContent has been deleted (if aBinding is null and the content node
   // dies before we process mAttachedStack).
   nsRefPtr<nsXBLBinding> oldBinding = GetXBLBinding();
   if (oldBinding) {
     bindingManager->RemoveFromAttachedQueue(oldBinding);
   }
 
-  nsDOMSlots *slots = DOMSlots();
   if (aBinding) {
     SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
+    nsDOMSlots *slots = DOMSlots();
     slots->mXBLBinding = aBinding;
     bindingManager->AddBoundContent(this);
   } else {
-    slots->mXBLBinding = nullptr;
+    nsDOMSlots *slots = GetExistingDOMSlots();
+    if (slots) {
+      slots->mXBLBinding = nullptr;
+    }
     bindingManager->RemoveBoundContent(this);
     if (oldBinding) {
       oldBinding->SetBoundElement(nullptr);
     }
   }
 }
 
 nsIContent*
@@ -1006,21 +1009,26 @@ FragmentOrElement::SetShadowRoot(ShadowR
 {
   nsDOMSlots *slots = DOMSlots();
   slots->mShadowRoot = aShadowRoot;
 }
 
 void
 FragmentOrElement::SetXBLInsertionParent(nsIContent* aContent)
 {
-  nsDOMSlots *slots = DOMSlots();
   if (aContent) {
+    nsDOMSlots *slots = DOMSlots();
     SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
+    slots->mXBLInsertionParent = aContent;
+  } else {
+    nsDOMSlots *slots = GetExistingDOMSlots();
+    if (slots) {
+      slots->mXBLInsertionParent = nullptr;
+    }
   }
-  slots->mXBLInsertionParent = aContent;
 }
 
 CustomElementData*
 FragmentOrElement::GetCustomElementData() const
 {
   nsDOMSlots *slots = GetExistingDOMSlots();
   if (slots) {
     return slots->mCustomElementData;
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -708,21 +708,26 @@ nsGenericDOMDataNode::GetXBLInsertionPar
   }
 
   return nullptr;
 }
 
 void
 nsGenericDOMDataNode::SetXBLInsertionParent(nsIContent* aContent)
 {
-  nsDataSlots *slots = DataSlots();
   if (aContent) {
+    nsDataSlots *slots = DataSlots();
     SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
+    slots->mXBLInsertionParent = aContent;
+  } else {
+    nsDataSlots *slots = GetExistingDataSlots();
+    if (slots) {
+      slots->mXBLInsertionParent = nullptr;
+    }
   }
-  slots->mXBLInsertionParent = aContent;
 }
 
 CustomElementData *
 nsGenericDOMDataNode::GetCustomElementData() const
 {
   return nullptr;
 }