diff options
author | Steve Block <steveblock@google.com> | 2010-02-15 12:23:52 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-16 11:48:32 +0000 |
commit | 8a0914b749bbe7da7768e07a7db5c6d4bb09472b (patch) | |
tree | 73f9065f370435d6fde32ae129d458a8c77c8dff /JavaScriptCore/wtf/PassRefPtr.h | |
parent | bf14be70295513b8076f3fa47a268a7e42b2c478 (diff) | |
download | external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.zip external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.gz external_webkit-8a0914b749bbe7da7768e07a7db5c6d4bb09472b.tar.bz2 |
Merge webkit.org at r54731 : Initial merge by git
Change-Id: Ia79977b6cf3b0b00c06ef39419989b28e57e4f4a
Diffstat (limited to 'JavaScriptCore/wtf/PassRefPtr.h')
-rw-r--r-- | JavaScriptCore/wtf/PassRefPtr.h | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/JavaScriptCore/wtf/PassRefPtr.h b/JavaScriptCore/wtf/PassRefPtr.h index 36ba78e..9c6e44f 100644 --- a/JavaScriptCore/wtf/PassRefPtr.h +++ b/JavaScriptCore/wtf/PassRefPtr.h @@ -28,10 +28,21 @@ namespace WTF { template<typename T> class RefPtr; template<typename T> class PassRefPtr; template <typename T> PassRefPtr<T> adoptRef(T*); - - // Remove inline for winscw compiler to prevent the compiler agressively resolving - // T::deref(), which will fail compiling when PassRefPtr<T> is used as class member - // or function arguments before T is defined. + + + // Remove inline for WINSCW compiler to prevent the compiler agressively resolving + // T::ref() and T::deref(), which will fail compiling when PassRefPtr<T> is used as + // a class member or function arguments before T is defined. + template<typename T> +#if !COMPILER(WINSCW) + inline +#endif + void refIfNotNull(T* ptr) + { + if (UNLIKELY(ptr != 0)) + ptr->ref(); + } + template<typename T> #if !COMPILER(WINSCW) inline @@ -45,7 +56,7 @@ namespace WTF { template<typename T> class PassRefPtr { public: PassRefPtr() : m_ptr(0) {} - PassRefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } + PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } // It somewhat breaks the type system to allow transfer of ownership out of // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr // temporaries, and we don't really have a need to use real const PassRefPtrs @@ -53,14 +64,14 @@ namespace WTF { PassRefPtr(const PassRefPtr& o) : m_ptr(o.releaseRef()) {} template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { } - ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull<T>(m_ptr); } + ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } template <class U> - PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); } + PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } T* get() const { return m_ptr; } - void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; } + void clear() { T* ptr = m_ptr; derefIfNotNull(ptr); m_ptr = 0; } T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; } T& operator*() const { return *m_ptr; } @@ -143,23 +154,19 @@ namespace WTF { template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o) { T* optr = o.get(); - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr) { - if (optr) - optr->ref(); + refIfNotNull(optr); T* ptr = m_ptr; m_ptr = optr; - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -167,8 +174,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = ref.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } @@ -176,8 +182,7 @@ namespace WTF { { T* ptr = m_ptr; m_ptr = ref.releaseRef(); - if (ptr) - ptr->deref(); + derefIfNotNull(ptr); return *this; } |