Title: [101448] trunk/Source/_javascript_Core
Revision
101448
Author
wei...@apple.com
Date
2011-11-29 21:42:14 -0800 (Tue, 29 Nov 2011)

Log Message

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

Reviewed by Anders Carlsson.

* wtf/RetainPtr.h:
(WTF::RetainPtr::RetainPtr):
Add a move constructor and move enabled assignment operators
to RetainPtr if the compiler being used supports rvalue
references. If the compiler does not support it, we fallback
to the copy semantics we have always had.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (101447 => 101448)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-30 05:39:07 UTC (rev 101447)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-30 05:42:14 UTC (rev 101448)
@@ -1,3 +1,17 @@
+2011-11-29  Sam Weinig  <s...@webkit.org>
+
+        Add move semantics to RetainPtr
+        https://bugs.webkit.org/show_bug.cgi?id=73393
+
+        Reviewed by Anders Carlsson.
+
+        * wtf/RetainPtr.h:
+        (WTF::RetainPtr::RetainPtr):
+        Add a move constructor and move enabled assignment operators
+        to RetainPtr if the compiler being used supports rvalue
+        references. If the compiler does not support it, we fallback
+        to the copy semantics we have always had.
+
 2011-11-29  Yuqiang Xian  <yuqiang.x...@intel.com>
 
         DFG local CSE may cause incorrect reference counting for a node

Modified: trunk/Source/_javascript_Core/wtf/RetainPtr.h (101447 => 101448)


--- trunk/Source/_javascript_Core/wtf/RetainPtr.h	2011-11-30 05:39:07 UTC (rev 101447)
+++ trunk/Source/_javascript_Core/wtf/RetainPtr.h	2011-11-30 05:42:14 UTC (rev 101448)
@@ -65,6 +65,10 @@
         
         RetainPtr(const RetainPtr& o) : m_ptr(o.m_ptr) { if (PtrType ptr = m_ptr) CFRetain(ptr); }
 
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+        RetainPtr(RetainPtr&& o) : m_ptr(o.leakRef()) { }
+#endif
+
         // Hash table deleted values, which are only constructed and never copied or destroyed.
         RetainPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
         bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
@@ -90,6 +94,12 @@
         template<typename U> RetainPtr& operator=(const RetainPtr<U>&);
         RetainPtr& operator=(PtrType);
         template<typename U> RetainPtr& operator=(U*);
+
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+        RetainPtr& operator=(RetainPtr&&);
+        template<typename U> RetainPtr& operator=(RetainPtr<U>&&);
+#endif
+
 #if !HAVE(NULLPTR)
         RetainPtr& operator=(std::nullptr_t) { clear(); return *this; }
 #endif
@@ -153,7 +163,7 @@
             CFRelease(ptr);
         return *this;
     }
-    
+
     template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(PtrType optr)
     {
         if (optr)
@@ -165,33 +175,47 @@
         return *this;
     }
 
-    template<typename T> inline void RetainPtr<T>::adoptCF(PtrType optr)
+    template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)
     {
+        if (optr)
+            CFRetain(optr);
         PtrType ptr = m_ptr;
         m_ptr = optr;
         if (ptr)
             CFRelease(ptr);
+        return *this;
     }
 
-    template<typename T> inline void RetainPtr<T>::adoptNS(PtrType optr)
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+    template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(RetainPtr<T>&& o)
     {
-        adoptNSReference(optr);
-        
+        adoptCF(leakRef());
+        return *this;
+    }
+    
+    template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(RetainPtr<U>&& o)
+    {
+        adoptCF(leakRef());
+        return *this;
+    }
+#endif
+
+    template<typename T> inline void RetainPtr<T>::adoptCF(PtrType optr)
+    {
         PtrType ptr = m_ptr;
         m_ptr = optr;
         if (ptr)
             CFRelease(ptr);
     }
-    
-    template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)
+
+    template<typename T> inline void RetainPtr<T>::adoptNS(PtrType optr)
     {
-        if (optr)
-            CFRetain(optr);
+        adoptNSReference(optr);
+        
         PtrType ptr = m_ptr;
         m_ptr = optr;
         if (ptr)
             CFRelease(ptr);
-        return *this;
     }
 
     template<typename T> inline void RetainPtr<T>::swap(RetainPtr<T>& o)
@@ -233,7 +257,7 @@
     { 
         return a != b.get(); 
     }
-    
+
     template<typename P> struct HashTraits<RetainPtr<P> > : SimpleClassHashTraits<RetainPtr<P> > { };
     
     template<typename P> struct PtrHash<RetainPtr<P> > : PtrHash<typename RetainPtr<P>::PtrType> {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to