| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reser
ved. |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 T* get() const { return m_ptr; } | 77 T* get() const { return m_ptr; } |
| 78 | 78 |
| 79 T* leakRef() const WARN_UNUSED_RETURN; | 79 T* leakRef() const WARN_UNUSED_RETURN; |
| 80 | 80 |
| 81 T& operator*() const { return *m_ptr; } | 81 T& operator*() const { return *m_ptr; } |
| 82 T* operator->() const { return m_ptr; } | 82 T* operator->() const { return m_ptr; } |
| 83 | 83 |
| 84 bool operator!() const { return !m_ptr; } | 84 bool operator!() const { return !m_ptr; } |
| 85 | 85 |
| 86 // This conversion operator allows implicit conversion to bool but not to | 86 // TODO(jbroman): Simplifying this in the obvious way causes a massive |
| 87 // other integer types. | 87 // regression in a perf test on ARM. http://crbug.com/607208 |
| 88 typedef T* (PassRefPtr::*UnspecifiedBoolType); | 88 explicit operator bool() const { return m_ptr ? &PassRefPtr::m_ptr : 0; } |
| 89 operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::m_ptr : 0
; } | |
| 90 | 89 |
| 91 friend PassRefPtr adoptRef<T>(T*); | 90 friend PassRefPtr adoptRef<T>(T*); |
| 92 | 91 |
| 93 private: | 92 private: |
| 94 enum AdoptRefTag { AdoptRef }; | 93 enum AdoptRefTag { AdoptRef }; |
| 95 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {} | 94 PassRefPtr(T* ptr, AdoptRefTag) : m_ptr(ptr) {} |
| 96 | 95 |
| 97 PassRefPtr& operator=(const PassRefPtr&) | 96 PassRefPtr& operator=(const PassRefPtr&) |
| 98 { | 97 { |
| 99 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); | 98 static_assert(!sizeof(T*), "PassRefPtr should never be assigned to"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a,
U* b) | 141 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a,
U* b) |
| 143 { | 142 { |
| 144 return a.get() == b; | 143 return a.get() == b; |
| 145 } | 144 } |
| 146 | 145 |
| 147 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<
U>& b) | 146 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<
U>& b) |
| 148 { | 147 { |
| 149 return a == b.get(); | 148 return a == b.get(); |
| 150 } | 149 } |
| 151 | 150 |
| 151 template <typename T> inline bool operator==(const PassRefPtr<T>& a, std::nullpt
r_t) |
| 152 { |
| 153 return !a.get(); |
| 154 } |
| 155 |
| 156 template <typename T> inline bool operator==(std::nullptr_t, const PassRefPtr<T>
& b) |
| 157 { |
| 158 return !b.get(); |
| 159 } |
| 160 |
| 152 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const PassRefPtr<U>& b) | 161 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const PassRefPtr<U>& b) |
| 153 { | 162 { |
| 154 return a.get() != b.get(); | 163 return a.get() != b.get(); |
| 155 } | 164 } |
| 156 | 165 |
| 157 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const RefPtr<U>& b) | 166 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
const RefPtr<U>& b) |
| 158 { | 167 { |
| 159 return a.get() != b.get(); | 168 return a.get() != b.get(); |
| 160 } | 169 } |
| 161 | 170 |
| 162 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st PassRefPtr<U>& b) | 171 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, con
st PassRefPtr<U>& b) |
| 163 { | 172 { |
| 164 return a.get() != b.get(); | 173 return a.get() != b.get(); |
| 165 } | 174 } |
| 166 | 175 |
| 167 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
U* b) | 176 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a,
U* b) |
| 168 { | 177 { |
| 169 return a.get() != b; | 178 return a.get() != b; |
| 170 } | 179 } |
| 171 | 180 |
| 172 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<
U>& b) | 181 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<
U>& b) |
| 173 { | 182 { |
| 174 return a != b.get(); | 183 return a != b.get(); |
| 175 } | 184 } |
| 176 | 185 |
| 186 template <typename T> inline bool operator!=(const PassRefPtr<T>& a, std::nullpt
r_t) |
| 187 { |
| 188 return a.get(); |
| 189 } |
| 190 |
| 191 template <typename T> inline bool operator!=(std::nullptr_t, const PassRefPtr<T>
& b) |
| 192 { |
| 193 return b.get(); |
| 194 } |
| 195 |
| 177 template <typename T> PassRefPtr<T> adoptRef(T* p) | 196 template <typename T> PassRefPtr<T> adoptRef(T* p) |
| 178 { | 197 { |
| 179 adopted(p); | 198 adopted(p); |
| 180 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); | 199 return PassRefPtr<T>(p, PassRefPtr<T>::AdoptRef); |
| 181 } | 200 } |
| 182 | 201 |
| 183 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const
PassRefPtr<U>& p) | 202 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const
PassRefPtr<U>& p) |
| 184 { | 203 { |
| 185 return adoptRef(static_cast<T*>(p.leakRef())); | 204 return adoptRef(static_cast<T*>(p.leakRef())); |
| 186 } | 205 } |
| 187 | 206 |
| 188 template <typename T> inline T* getPtr(const PassRefPtr<T>& p) | 207 template <typename T> inline T* getPtr(const PassRefPtr<T>& p) |
| 189 { | 208 { |
| 190 return p.get(); | 209 return p.get(); |
| 191 } | 210 } |
| 192 | 211 |
| 193 } // namespace WTF | 212 } // namespace WTF |
| 194 | 213 |
| 195 using WTF::PassRefPtr; | 214 using WTF::PassRefPtr; |
| 196 using WTF::adoptRef; | 215 using WTF::adoptRef; |
| 197 using WTF::static_pointer_cast; | 216 using WTF::static_pointer_cast; |
| 198 | 217 |
| 199 #endif // WTF_PassRefPtr_h | 218 #endif // WTF_PassRefPtr_h |
| OLD | NEW |