bug 980753 - make nsRefPtr movable r=froydnj
authorTrevor Saunders <trev.saunders@gmail.com>
Wed, 26 Feb 2014 18:11:14 -0500
changeset 180573 db9956f946806e470240236b1c9af7c37276d487
parent 180572 1bab9339e6d427eb6d5745ccdd2358027c2c4cbf
child 180574 fd5d78e32b56d3397b3ad384b09125e1d77f94bf
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersfroydnj
bugs980753
milestone31.0a1
bug 980753 - make nsRefPtr movable r=froydnj
xpcom/base/nsAutoPtr.h
--- a/xpcom/base/nsAutoPtr.h
+++ b/xpcom/base/nsAutoPtr.h
@@ -897,27 +897,34 @@ class nsRefPtr
         // Constructors
 
       nsRefPtr()
             : mRawPtr(0)
           // default constructor
         {
         }
 
-      nsRefPtr( const nsRefPtr<T>& aSmartPtr )
+      nsRefPtr(const nsRefPtr<T>& aSmartPtr)
             : mRawPtr(aSmartPtr.mRawPtr)
           // copy-constructor
         {
           if ( mRawPtr )
             mRawPtr->AddRef();
         }
 
-      nsRefPtr( T* aRawPtr )
-            : mRawPtr(aRawPtr)
-          // construct from a raw pointer (of the right type)
+      nsRefPtr(nsRefPtr<T>&& aRefPtr)
+            : mRawPtr(aRefPtr.mRawPtr)
+        {
+          aRefPtr.mRawPtr = nullptr;
+        }
+
+      // construct from a raw pointer (of the right type)
+
+      nsRefPtr(T* aRawPtr)
+        : mRawPtr(aRawPtr)
         {
           if ( mRawPtr )
             mRawPtr->AddRef();
         }
 
       template <typename I>
       nsRefPtr( already_AddRefed<I>& aSmartPtr )
             : mRawPtr(aSmartPtr.take())
@@ -938,17 +945,17 @@ class nsRefPtr
           if (NS_FAILED(helper(NS_GET_TEMPLATE_IID(T), &newRawPtr)))
             newRawPtr = 0;
           mRawPtr = static_cast<T*>(newRawPtr);
         }
 
         // Assignment operators
 
       nsRefPtr<T>&
-      operator=( const nsRefPtr<T>& rhs )
+      operator=(const nsRefPtr<T>& rhs)
           // copy assignment operator
         {
           assign_with_AddRef(rhs.mRawPtr);
           return *this;
         }
 
       nsRefPtr<T>&
       operator=( T* rhs )
@@ -981,16 +988,24 @@ class nsRefPtr
         {
           void* newRawPtr;
           if (NS_FAILED(helper(NS_GET_TEMPLATE_IID(T), &newRawPtr)))
             newRawPtr = 0;
           assign_assuming_AddRef(static_cast<T*>(newRawPtr));
           return *this;
         }
 
+      nsRefPtr<T>&
+      operator=(nsRefPtr<T>&& aRefPtr)
+      {
+        assign_assuming_AddRef(aRefPtr.mRawPtr);
+        aRefPtr.mRawPtr = nullptr;
+        return *this;
+      }
+
         // Other pointer operators
 
       void
       swap( nsRefPtr<T>& rhs )
           // ...exchange ownership with |rhs|; can save a pair of refcount operations
         {
           T* temp = rhs.mRawPtr;
           rhs.mRawPtr = mRawPtr;