| 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 15 matching lines...) Expand all Loading... |
| 26 #include <wtf/NullPtr.h> | 26 #include <wtf/NullPtr.h> |
| 27 | 27 |
| 28 namespace WTF { | 28 namespace WTF { |
| 29 | 29 |
| 30 template<typename T> class RefPtr; | 30 template<typename T> class RefPtr; |
| 31 template<typename T> class PassRefPtr; | 31 template<typename T> class PassRefPtr; |
| 32 template<typename T> PassRefPtr<T> adoptRef(T*); | 32 template<typename T> PassRefPtr<T> adoptRef(T*); |
| 33 | 33 |
| 34 inline void adopted(const void*) { } | 34 inline void adopted(const void*) { } |
| 35 | 35 |
| 36 #if !(PLATFORM(QT) && CPU(ARM)) | 36 template<typename T> ALWAYS_INLINE void refIfNotNull(T* ptr) |
| 37 #define REF_DEREF_INLINE ALWAYS_INLINE | |
| 38 #else | |
| 39 // Older version of gcc used by Harmattan SDK fails to build with ALWAYS_INL
INE. | |
| 40 // See https://bugs.webkit.org/show_bug.cgi?id=37253 for details. | |
| 41 #define REF_DEREF_INLINE inline | |
| 42 #endif | |
| 43 | |
| 44 template<typename T> REF_DEREF_INLINE void refIfNotNull(T* ptr) | |
| 45 { | 37 { |
| 46 if (LIKELY(ptr != 0)) | 38 if (LIKELY(ptr != 0)) |
| 47 ptr->ref(); | 39 ptr->ref(); |
| 48 } | 40 } |
| 49 | 41 |
| 50 template<typename T> REF_DEREF_INLINE void derefIfNotNull(T* ptr) | 42 template<typename T> ALWAYS_INLINE void derefIfNotNull(T* ptr) |
| 51 { | 43 { |
| 52 if (LIKELY(ptr != 0)) | 44 if (LIKELY(ptr != 0)) |
| 53 ptr->deref(); | 45 ptr->deref(); |
| 54 } | 46 } |
| 55 | 47 |
| 56 #undef REF_DEREF_INLINE | |
| 57 | |
| 58 template<typename T> class PassRefPtr { | 48 template<typename T> class PassRefPtr { |
| 59 public: | 49 public: |
| 60 PassRefPtr() : m_ptr(0) { } | 50 PassRefPtr() : m_ptr(0) { } |
| 61 PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } | 51 PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } |
| 62 // It somewhat breaks the type system to allow transfer of ownership out
of | 52 // It somewhat breaks the type system to allow transfer of ownership out
of |
| 63 // a const PassRefPtr. However, it makes it much easier to work with Pas
sRefPtr | 53 // a const PassRefPtr. However, it makes it much easier to work with Pas
sRefPtr |
| 64 // temporaries, and we don't have a need to use real const PassRefPtrs a
nyway. | 54 // temporaries, and we don't have a need to use real const PassRefPtrs a
nyway. |
| 65 PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { } | 55 PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { } |
| 66 template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.leakRe
f()) { } | 56 template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.leakRe
f()) { } |
| 67 | 57 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 169 } |
| 180 | 170 |
| 181 } // namespace WTF | 171 } // namespace WTF |
| 182 | 172 |
| 183 using WTF::PassRefPtr; | 173 using WTF::PassRefPtr; |
| 184 using WTF::adoptRef; | 174 using WTF::adoptRef; |
| 185 using WTF::static_pointer_cast; | 175 using WTF::static_pointer_cast; |
| 186 using WTF::const_pointer_cast; | 176 using WTF::const_pointer_cast; |
| 187 | 177 |
| 188 #endif // WTF_PassRefPtr_h | 178 #endif // WTF_PassRefPtr_h |
| OLD | NEW |