Changeset 54724 in webkit for trunk/JavaScriptCore/wtf/PassRefPtr.h
- Timestamp:
- Feb 12, 2010, 6:29:02 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/PassRefPtr.h
r48836 r54724 29 29 template<typename T> class PassRefPtr; 30 30 template <typename T> PassRefPtr<T> adoptRef(T*); 31 32 // Remove inline for winscw compiler to prevent the compiler agressively resolving 33 // T::deref(), which will fail compiling when PassRefPtr<T> is used as class member 34 // or function arguments before T is defined. 31 32 33 // Remove inline for WINSCW compiler to prevent the compiler agressively resolving 34 // T::ref() and T::deref(), which will fail compiling when PassRefPtr<T> is used as 35 // a class member or function arguments before T is defined. 36 template<typename T> 37 #if !COMPILER(WINSCW) 38 inline 39 #endif 40 void refIfNotNull(T* ptr) 41 { 42 if (UNLIKELY(ptr != 0)) 43 ptr->ref(); 44 } 45 35 46 template<typename T> 36 47 #if !COMPILER(WINSCW) … … 46 57 public: 47 58 PassRefPtr() : m_ptr(0) {} 48 PassRefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }59 PassRefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } 49 60 // It somewhat breaks the type system to allow transfer of ownership out of 50 61 // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr … … 54 65 template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { } 55 66 56 ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull <T>(m_ptr); }67 ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } 57 68 58 69 template <class U> 59 PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); }70 PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } 60 71 61 72 T* get() const { return m_ptr; } 62 73 63 void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; }74 void clear() { T* ptr = m_ptr; derefIfNotNull(ptr); m_ptr = 0; } 64 75 T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; } 65 76 … … 144 155 { 145 156 T* optr = o.get(); 146 if (optr) 147 optr->ref(); 157 refIfNotNull(optr); 148 158 T* ptr = m_ptr; 149 159 m_ptr = optr; 150 if (ptr) 151 ptr->deref(); 160 derefIfNotNull(ptr); 152 161 return *this; 153 162 } … … 155 164 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr) 156 165 { 157 if (optr) 158 optr->ref(); 166 refIfNotNull(optr); 159 167 T* ptr = m_ptr; 160 168 m_ptr = optr; 161 if (ptr) 162 ptr->deref(); 169 derefIfNotNull(ptr); 163 170 return *this; 164 171 } … … 168 175 T* ptr = m_ptr; 169 176 m_ptr = ref.releaseRef(); 170 if (ptr) 171 ptr->deref(); 177 derefIfNotNull(ptr); 172 178 return *this; 173 179 } … … 177 183 T* ptr = m_ptr; 178 184 m_ptr = ref.releaseRef(); 179 if (ptr) 180 ptr->deref(); 185 derefIfNotNull(ptr); 181 186 return *this; 182 187 }
Note:
See TracChangeset
for help on using the changeset viewer.