bug 980753 - make nsRefPtr movable r=froydnj
authorTrevor Saunders <trev.saunders@gmail.com>
Wed, 26 Feb 2014 18:11:14 -0500
changeset 198664 db9956f946806e470240236b1c9af7c37276d487
parent 198663 1bab9339e6d427eb6d5745ccdd2358027c2c4cbf
child 198665 fd5d78e32b56d3397b3ad384b09125e1d77f94bf
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs980753
milestone31.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 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;