Bug 1563405, part 2 - Use move refs for Push in nsXULContentSink. r=bzbarsky
authorAndrew McCreight <continuation@gmail.com>
Thu, 04 Jul 2019 05:55:54 +0000
changeset 544087 dfe7d3650300443755a77f6166bacb5787f11b47
parent 544086 a4f406edcb1af929d53b20e8f39c5acbd835d370
child 544088 e41e92ec3f2f966939c30aa5024216676376c5dd
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1563405
milestone69.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 1563405, part 2 - Use move refs for Push in nsXULContentSink. r=bzbarsky This avoids some refcounting. Also remove a pointless local variable |entry|. Differential Revision: https://phabricator.services.mozilla.com/D36846
dom/xul/nsXULContentSink.cpp
dom/xul/nsXULContentSink.h
--- a/dom/xul/nsXULContentSink.cpp
+++ b/dom/xul/nsXULContentSink.cpp
@@ -61,22 +61,19 @@ XULContentSinkImpl::ContextStack::Contex
 XULContentSinkImpl::ContextStack::~ContextStack() {
   while (mTop) {
     Entry* doomed = mTop;
     mTop = mTop->mNext;
     delete doomed;
   }
 }
 
-void XULContentSinkImpl::ContextStack::Push(nsXULPrototypeNode* aNode,
+void XULContentSinkImpl::ContextStack::Push(RefPtr<nsXULPrototypeNode>&& aNode,
                                             State aState) {
-  Entry* entry = new Entry(aNode, aState, mTop);
-
-  mTop = entry;
-
+  mTop = new Entry(std::move(aNode), aState, mTop);
   ++mDepth;
 }
 
 nsresult XULContentSinkImpl::ContextStack::Pop(State* aState) {
   if (mDepth == 0) return NS_ERROR_UNEXPECTED;
 
   Entry* entry = mTop;
   mTop = mTop->mNext;
@@ -627,17 +624,17 @@ nsresult XULContentSinkImpl::OpenRoot(co
   RefPtr<nsXULPrototypeElement> element = new nsXULPrototypeElement(aNodeInfo);
 
   // Add the attributes
   nsresult rv = AddAttributes(aAttributes, aAttrLen, element);
   if (NS_FAILED(rv)) return rv;
 
   // Push the element onto the context stack, so that child
   // containers will hook up to us as their parent.
-  mContextStack.Push(element, mState);
+  mContextStack.Push(std::move(element), mState);
 
   mState = eInDocumentElement;
   return NS_OK;
 }
 
 nsresult XULContentSinkImpl::OpenTag(const char16_t** aAttributes,
                                      const uint32_t aAttrLen,
                                      const uint32_t aLineNumber,
@@ -670,17 +667,17 @@ nsresult XULContentSinkImpl::OpenTag(con
       // OpenScript has pushed the nsPrototypeScriptElement onto the
       // stack, so we're done.
       return NS_OK;
     }
   }
 
   // Push the element onto the context stack, so that child
   // containers will hook up to us as their parent.
-  mContextStack.Push(element, mState);
+  mContextStack.Push(std::move(element), mState);
 
   mState = eInDocumentElement;
   return NS_OK;
 }
 
 nsresult XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
                                         const uint32_t aLineNumber) {
   bool isJavaScript = true;
--- a/dom/xul/nsXULContentSink.h
+++ b/dom/xul/nsXULContentSink.h
@@ -97,30 +97,33 @@ class XULContentSinkImpl final : public 
   class ContextStack {
    protected:
     struct Entry {
       RefPtr<nsXULPrototypeNode> mNode;
       // a LOT of nodes have children; preallocate for 8
       nsPrototypeArray mChildren;
       State mState;
       Entry* mNext;
-      Entry(nsXULPrototypeNode* aNode, State aState, Entry* aNext)
-          : mNode(aNode), mChildren(8), mState(aState), mNext(aNext) {}
+      Entry(RefPtr<nsXULPrototypeNode>&& aNode, State aState, Entry* aNext)
+          : mNode(std::move(aNode)),
+            mChildren(8),
+            mState(aState),
+            mNext(aNext) {}
     };
 
     Entry* mTop;
     int32_t mDepth;
 
    public:
     ContextStack();
     ~ContextStack();
 
     int32_t Depth() { return mDepth; }
 
-    void Push(nsXULPrototypeNode* aNode, State aState);
+    void Push(RefPtr<nsXULPrototypeNode>&& aNode, State aState);
     nsresult Pop(State* aState);
 
     nsresult GetTopNode(RefPtr<nsXULPrototypeNode>& aNode);
     nsresult GetTopChildren(nsPrototypeArray** aChildren);
 
     void Clear();
 
     void Traverse(nsCycleCollectionTraversalCallback& aCallback);