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

Unified Diff: third_party/WebKit/Source/wtf/PassOwnPtr.h

Issue 1917193006: WTF: Make PassOwnPtr<T> move-only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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 | « third_party/WebKit/Source/wtf/OwnPtr.h ('k') | third_party/WebKit/public/platform/WebBlobData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/PassOwnPtr.h
diff --git a/third_party/WebKit/Source/wtf/PassOwnPtr.h b/third_party/WebKit/Source/wtf/PassOwnPtr.h
index 131cb381798fbc7a3498bdcbf64db7bf16be3618..eb9a85c3fd4efeab09522ce84983e81a4ad85237 100644
--- a/third_party/WebKit/Source/wtf/PassOwnPtr.h
+++ b/third_party/WebKit/Source/wtf/PassOwnPtr.h
@@ -47,18 +47,14 @@ public:
PassOwnPtr() : m_ptr(nullptr) {}
PassOwnPtr(std::nullptr_t) : m_ptr(nullptr) {}
- // It somewhat breaks the type system to allow transfer of ownership out of
- // a const PassOwnPtr. However, it makes it much easier to work with
- // PassOwnPtr temporaries, and we don't have a need to use real const
- // PassOwnPtrs anyway.
- PassOwnPtr(const PassOwnPtr& o) : m_ptr(o.leakPtr()) {}
- template <typename U> PassOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibleArgDecl(U, T));
+ PassOwnPtr(PassOwnPtr&& o) : m_ptr(o.leakPtr()) {}
+ template <typename U> PassOwnPtr(PassOwnPtr<U>&&, EnsurePtrConvertibleArgDecl(U, T));
~PassOwnPtr() { OwnedPtrDeleter<T>::deletePtr(m_ptr); }
PtrType get() const { return m_ptr; }
- PtrType leakPtr() const WARN_UNUSED_RETURN;
+ PtrType leakPtr() WARN_UNUSED_RETURN;
ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; }
PtrType operator->() const { ASSERT(m_ptr); return m_ptr; }
@@ -73,6 +69,7 @@ public:
private:
explicit PassOwnPtr(PtrType ptr) : m_ptr(ptr) {}
+ PassOwnPtr(const PassOwnPtr&) = delete;
PassOwnPtr& operator=(const PassOwnPtr&) = delete;
// We should never have two OwnPtrs for the same underlying object
@@ -83,17 +80,17 @@ private:
template <typename U> bool operator==(const OwnPtr<U>&) const = delete;
template <typename U> bool operator!=(const OwnPtr<U>&) const = delete;
- mutable PtrType m_ptr;
+ PtrType m_ptr;
};
template <typename T>
-template <typename U> inline PassOwnPtr<T>::PassOwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
+template <typename U> inline PassOwnPtr<T>::PassOwnPtr(PassOwnPtr<U>&& o, EnsurePtrConvertibleArgDefn(U, T))
: m_ptr(o.leakPtr())
{
static_assert(!std::is_array<T>::value, "pointers to array must never be converted");
}
-template <typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::leakPtr() const
+template <typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::leakPtr()
{
PtrType ptr = m_ptr;
m_ptr = nullptr;
@@ -130,7 +127,7 @@ template <typename T> inline PassOwnPtr<T[]> adoptArrayPtr(T* ptr)
return PassOwnPtr<T[]>(ptr);
}
-template <typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(const PassOwnPtr<U>& p)
+template <typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(PassOwnPtr<U>&& p)
{
static_assert(!std::is_array<T>::value, "pointers to array must never be converted");
return adoptPtr(static_cast<T*>(p.leakPtr()));
« no previous file with comments | « third_party/WebKit/Source/wtf/OwnPtr.h ('k') | third_party/WebKit/public/platform/WebBlobData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698