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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 PassRefPtr<T> tmp = adoptRef(m_ptr); 64 PassRefPtr<T> tmp = adoptRef(m_ptr);
65 m_ptr = nullptr; 65 m_ptr = nullptr;
66 return tmp; 66 return tmp;
67 } 67 }
68 68
69 T& operator*() const { return *m_ptr; } 69 T& operator*() const { return *m_ptr; }
70 ALWAYS_INLINE T* operator->() const { return m_ptr; } 70 ALWAYS_INLINE T* operator->() const { return m_ptr; }
71 71
72 bool operator!() const { return !m_ptr; } 72 bool operator!() const { return !m_ptr; }
73 73
74 // This conversion operator allows implicit conversion to bool but not to 74 // TODO(jbroman): Simplifying this in the obvious way causes a massive
75 // other integer types. 75 // regression in a perf test on ARM. http://crbug.com/607208
76 typedef T* (RefPtr::*UnspecifiedBoolType); 76 explicit operator bool() const { return m_ptr ? &RefPtr::m_ptr : 0; }
77 operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
78 77
79 RefPtr& operator=(RefPtr o) { swap(o); return *this; } 78 RefPtr& operator=(RefPtr o) { swap(o); return *this; }
80 RefPtr& operator=(std::nullptr_t) { clear(); return *this; } 79 RefPtr& operator=(std::nullptr_t) { clear(); return *this; }
81 // This is required by HashMap<RefPtr>>. 80 // This is required by HashMap<RefPtr>>.
82 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>); 81 template <typename U> RefPtr& operator=(RefPtrValuePeeker<U>);
83 82
84 void swap(RefPtr&); 83 void swap(RefPtr&);
85 84
86 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } 85 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
87 86
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b) 127 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
129 { 128 {
130 return a.get() == b; 129 return a.get() == b;
131 } 130 }
132 131
133 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b) 132 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
134 { 133 {
135 return a == b.get(); 134 return a == b.get();
136 } 135 }
137 136
137 template <typename T> inline bool operator==(const RefPtr<T>& a, std::nullptr_t)
138 {
139 return !a.get();
140 }
141
142 template <typename T> inline bool operator==(std::nullptr_t, const RefPtr<T>& b)
143 {
144 return !b.get();
145 }
146
138 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st RefPtr<U>& b) 147 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con st RefPtr<U>& b)
139 { 148 {
140 return a.get() != b.get(); 149 return a.get() != b.get();
141 } 150 }
142 151
143 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b) 152 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
144 { 153 {
145 return a.get() != b; 154 return a.get() != b;
146 } 155 }
147 156
148 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b) 157 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
149 { 158 {
150 return a != b.get(); 159 return a != b.get();
151 } 160 }
152 161
162 template <typename T> inline bool operator!=(const RefPtr<T>& a, std::nullptr_t)
163 {
164 return a.get();
165 }
166
167 template <typename T> inline bool operator!=(std::nullptr_t, const RefPtr<T>& b)
168 {
169 return b.get();
170 }
171
153 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref Ptr<U>& p) 172 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const Ref Ptr<U>& p)
154 { 173 {
155 return RefPtr<T>(static_cast<T*>(p.get())); 174 return RefPtr<T>(static_cast<T*>(p.get()));
156 } 175 }
157 176
158 template <typename T> inline T* getPtr(const RefPtr<T>& p) 177 template <typename T> inline T* getPtr(const RefPtr<T>& p)
159 { 178 {
160 return p.get(); 179 return p.get();
161 } 180 }
162 181
163 template <typename T> class RefPtrValuePeeker { 182 template <typename T> class RefPtrValuePeeker {
164 DISALLOW_NEW(); 183 DISALLOW_NEW();
165 public: 184 public:
166 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {} 185 ALWAYS_INLINE RefPtrValuePeeker(T* p): m_ptr(p) {}
167 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {} 186 ALWAYS_INLINE RefPtrValuePeeker(std::nullptr_t): m_ptr(nullptr) {}
168 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get()) {} 187 template <typename U> RefPtrValuePeeker(const RefPtr<U>& p): m_ptr(p.get()) {}
169 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get ()) {} 188 template <typename U> RefPtrValuePeeker(const PassRefPtr<U>& p): m_ptr(p.get ()) {}
170 189
171 ALWAYS_INLINE operator T*() const { return m_ptr; } 190 ALWAYS_INLINE operator T*() const { return m_ptr; }
172 private: 191 private:
173 T* m_ptr; 192 T* m_ptr;
174 }; 193 };
175 194
176 } // namespace WTF 195 } // namespace WTF
177 196
178 using WTF::RefPtr; 197 using WTF::RefPtr;
179 using WTF::static_pointer_cast; 198 using WTF::static_pointer_cast;
180 199
181 #endif // WTF_RefPtr_h 200 #endif // WTF_RefPtr_h
OLDNEW
« 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