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

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

Issue 2063773002: Reland: WTF: Implement explicit RefPtr::operator bool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
Index: third_party/WebKit/Source/wtf/RefPtr.h
diff --git a/third_party/WebKit/Source/wtf/RefPtr.h b/third_party/WebKit/Source/wtf/RefPtr.h
index 4ed3ea5de07c16ca00103e0044387d07421dbaef..eab641a66509aeca93b469c0f35c46e30c7ac44b 100644
--- a/third_party/WebKit/Source/wtf/RefPtr.h
+++ b/third_party/WebKit/Source/wtf/RefPtr.h
@@ -71,10 +71,9 @@ public:
bool operator!() const { return !m_ptr; }
- // This conversion operator allows implicit conversion to bool but not to
- // other integer types.
- typedef T* (RefPtr::*UnspecifiedBoolType);
- operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
+ // TODO(jbroman): Simplifying this in the obvious way causes a massive
+ // regression in a perf test on ARM. http://crbug.com/607208
+ explicit operator bool() const { return m_ptr ? &RefPtr::m_ptr : 0; }
RefPtr& operator=(RefPtr o) { swap(o); return *this; }
RefPtr& operator=(std::nullptr_t) { clear(); return *this; }
@@ -135,6 +134,16 @@ template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>&
return a == b.get();
}
+template <typename T> inline bool operator==(const RefPtr<T>& a, std::nullptr_t)
+{
+ return !a.get();
+}
+
+template <typename T> inline bool operator==(std::nullptr_t, const RefPtr<T>& b)
+{
+ return !b.get();
+}
+
template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
{
return a.get() != b.get();
@@ -150,6 +159,16 @@ template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>&
return a != b.get();
}
+template <typename T> inline bool operator!=(const RefPtr<T>& a, std::nullptr_t)
+{
+ return a.get();
+}
+
+template <typename T> inline bool operator!=(std::nullptr_t, const RefPtr<T>& b)
+{
+ return b.get();
+}
+
template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
{
return RefPtr<T>(static_cast<T*>(p.get()));
« no previous file with comments | « third_party/WebKit/Source/wtf/PassRefPtr.h ('k') | third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698