Title: [149184] trunk/Source/WTF
Revision
149184
Author
mikhail.pozdnya...@intel.com
Date
2013-04-26 07:56:21 -0700 (Fri, 26 Apr 2013)

Log Message

Add move semantics to RefPtr
https://bugs.webkit.org/show_bug.cgi?id=115033

Reviewed by Anders Carlsson.

Add move constructors and move assignment operators to RefPtr when
COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES).
This obviates unnecessary reffing/ureffing when RefPtr is created
or assigned from rvalue references.

* wtf/RefPtr.h:
(RefPtr):
(WTF::RefPtr::RefPtr):
(WTF::RefPtr::operator=):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (149183 => 149184)


--- trunk/Source/WTF/ChangeLog	2013-04-26 14:32:22 UTC (rev 149183)
+++ trunk/Source/WTF/ChangeLog	2013-04-26 14:56:21 UTC (rev 149184)
@@ -1,3 +1,20 @@
+2013-04-26  Mikhail Pozdnyakov  <mikhail.pozdnya...@intel.com>
+
+        Add move semantics to RefPtr
+        https://bugs.webkit.org/show_bug.cgi?id=115033
+
+        Reviewed by Anders Carlsson.
+
+        Add move constructors and move assignment operators to RefPtr when
+        COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES).
+        This obviates unnecessary reffing/ureffing when RefPtr is created
+        or assigned from rvalue references.
+
+        * wtf/RefPtr.h:
+        (RefPtr):
+        (WTF::RefPtr::RefPtr):
+        (WTF::RefPtr::operator=):
+
 2013-04-26  Andreas Kling  <akl...@apple.com>
 
         Remove wxWebKit from WTF.

Modified: trunk/Source/WTF/wtf/RefPtr.h (149183 => 149184)


--- trunk/Source/WTF/wtf/RefPtr.h	2013-04-26 14:32:22 UTC (rev 149183)
+++ trunk/Source/WTF/wtf/RefPtr.h	2013-04-26 14:56:21 UTC (rev 149184)
@@ -24,6 +24,7 @@
 #define WTF_RefPtr_h
 
 #include <algorithm>
+#include <utility>
 #include <wtf/FastAllocBase.h>
 #include <wtf/PassRefPtr.h>
 
@@ -43,6 +44,11 @@
         ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); }
         template<typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { refIfNotNull(m_ptr); }
 
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+        ALWAYS_INLINE RefPtr(RefPtr&& o) : m_ptr(o.release().leakRef()) { }
+        template<typename U> RefPtr(RefPtr<U>&& o) : m_ptr(o.release().leakRef()) { }
+#endif
+
         // See comments in PassRefPtr.h for an explanation of why this takes a const reference.
         template<typename U> RefPtr(const PassRefPtr<U>&);
 
@@ -77,7 +83,10 @@
 #endif
         template<typename U> RefPtr& operator=(const RefPtr<U>&);
         template<typename U> RefPtr& operator=(const PassRefPtr<U>&);
-
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+        RefPtr& operator=(RefPtr&&);
+        template<typename U> RefPtr& operator=(RefPtr<U>&&);
+#endif
         void swap(RefPtr&);
 
         static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
@@ -142,7 +151,21 @@
         derefIfNotNull(ptr);
         return *this;
     }
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+    template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(RefPtr<T>&& o)
+    {
+        RefPtr<T> ptr = std::move(o);
+        swap(ptr);
+        return *this;
+    }
 
+    template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(RefPtr<U>&& o)
+    {
+        RefPtr<T> ptr = std::move(o);
+        swap(ptr);
+        return *this;
+    }
+#endif
     template<class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
     {
         std::swap(m_ptr, o.m_ptr);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to