Title: [101529] trunk/Source/WebKit2
Revision
101529
Author
[email protected]
Date
2011-11-30 10:26:27 -0800 (Wed, 30 Nov 2011)

Log Message

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

Reviewed by Anders Carlsson.

* UIProcess/API/cpp/WKRetainPtr.h:
(WebKit::WKRetainPtr::WKRetainPtr):
Add a move constructor and move enabled assignment operators
to WKRetainPtr 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/WebKit2/ChangeLog (101528 => 101529)


--- trunk/Source/WebKit2/ChangeLog	2011-11-30 18:25:50 UTC (rev 101528)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-30 18:26:27 UTC (rev 101529)
@@ -1,3 +1,17 @@
+2011-11-29  Sam Weinig  <[email protected]>
+
+        Add move semantics to WKRetainPtr
+        https://bugs.webkit.org/show_bug.cgi?id=73400
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/cpp/WKRetainPtr.h:
+        (WebKit::WKRetainPtr::WKRetainPtr):
+        Add a move constructor and move enabled assignment operators
+        to WKRetainPtr 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-30  Mario Sanchez Prada  <[email protected]>
 
         [Gtk] Links should be Tab-focusable by default

Modified: trunk/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h (101528 => 101529)


--- trunk/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h	2011-11-30 18:25:50 UTC (rev 101528)
+++ trunk/Source/WebKit2/UIProcess/API/cpp/WKRetainPtr.h	2011-11-30 18:26:27 UTC (rev 101529)
@@ -68,6 +68,18 @@
             WKRetain(ptr);
     }
 
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+    template<typename U> WKRetainPtr(WKRetainPtr<U>&& o)
+        : m_ptr(o.leakRef())
+    {
+    }
+    
+    WKRetainPtr(WKRetainPtr&& o)
+        : m_ptr(o.leakRef())
+    {
+    }
+#endif
+
     ~WKRetainPtr()
     {
         if (PtrType ptr = m_ptr)
@@ -103,6 +115,11 @@
     WKRetainPtr& operator=(PtrType);
     template<typename U> WKRetainPtr& operator=(U*);
 
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+    WKRetainPtr& operator=(WKRetainPtr&&);
+    template<typename U> WKRetainPtr& operator=(WKRetainPtr<U>&&);
+#endif
+
     void adopt(PtrType);
     void swap(WKRetainPtr&);
 
@@ -145,23 +162,37 @@
     return *this;
 }
 
-template<typename T> inline void WKRetainPtr<T>::adopt(PtrType optr)
+template<typename T> template<typename U> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(U* optr)
 {
+    if (optr)
+        WKRetain(optr);
     PtrType ptr = m_ptr;
     m_ptr = optr;
     if (ptr)
         WKRelease(ptr);
+    return *this;
 }
 
-template<typename T> template<typename U> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(U* optr)
+#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
+template<typename T> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(WKRetainPtr<T>&& o)
 {
-    if (optr)
-        WKRetain(optr);
+    adopt(o.leakRef());
+    return *this;
+}
+
+template<typename T> template<typename U> inline WKRetainPtr<T>& WKRetainPtr<T>::operator=(WKRetainPtr<U>&& o)
+{
+    adopt(o.leakRef());
+    return *this;
+}
+#endif
+
+template<typename T> inline void WKRetainPtr<T>::adopt(PtrType optr)
+{
     PtrType ptr = m_ptr;
     m_ptr = optr;
     if (ptr)
         WKRelease(ptr);
-    return *this;
 }
 
 template<typename T> inline void WKRetainPtr<T>::swap(WKRetainPtr<T>& o)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to