Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2159)

Unified Diff: Source/wtf/RefPtr.h

Issue 14031031: Add move semantics to RefPtr Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/RefPtr.h
diff --git a/Source/wtf/RefPtr.h b/Source/wtf/RefPtr.h
index 322cbd6f8f7b20555dda97f8ba46e8e628400519..2fa2251b866aab74ae528190ad6778f64d54bcd6 100644
--- a/Source/wtf/RefPtr.h
+++ b/Source/wtf/RefPtr.h
@@ -24,6 +24,7 @@
#define WTF_RefPtr_h
#include <algorithm>
+#include <utility>
#include <wtf/FastAllocBase.h>
#include <wtf/PassRefPtr.h>
@@ -43,6 +44,11 @@ namespace WTF {
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()) { }
Jeffrey Yasskin 2013/04/26 19:56:46 This looks correct, but you're not getting much be
+ template<typename U> RefPtr(RefPtr<U>&& o) : m_ptr(o.release().leakRef()) { }
Jeffrey Yasskin 2013/04/26 19:56:46 In the long run, we'll probably want to enable_if
+#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 @@ namespace WTF {
#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&&);
Jeffrey Yasskin 2013/04/26 19:56:46 I usually recommend writing operator= as RefPtr&
+ template<typename U> RefPtr& operator=(RefPtr<U>&&);
+#endif
void swap(RefPtr&);
static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
@@ -142,7 +151,21 @@ namespace WTF {
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698