Changeset 65130 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Aug 11, 2010, 12:08:23 AM (15 years ago)
- Location:
- trunk/JavaScriptCore/wtf
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/PassRefPtr.h
r63562 r65130 68 68 // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr 69 69 // temporaries, and we don't have a need to use real const PassRefPtrs anyway. 70 PassRefPtr(const PassRefPtr& o) : m_ptr(o. releaseRef()) { }71 template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o. releaseRef()) { }70 PassRefPtr(const PassRefPtr& o) : m_ptr(o.leakRef()) { } 71 template<typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.leakRef()) { } 72 72 73 73 ALWAYS_INLINE ~PassRefPtr() { derefIfNotNull(m_ptr); } … … 107 107 108 108 // NonNullPassRefPtr: Optimized for passing non-null pointers. A NonNullPassRefPtr 109 // begins life non-null, and can only become null through a call to releaseRef()109 // begins life non-null, and can only become null through a call to leakRef() 110 110 // or clear(). 111 111 … … 131 131 132 132 NonNullPassRefPtr(const NonNullPassRefPtr& o) 133 : m_ptr(o. releaseRef())133 : m_ptr(o.leakRef()) 134 134 { 135 135 ASSERT(m_ptr); … … 137 137 138 138 template<typename U> NonNullPassRefPtr(const NonNullPassRefPtr<U>& o) 139 : m_ptr(o. releaseRef())139 : m_ptr(o.leakRef()) 140 140 { 141 141 ASSERT(m_ptr); … … 143 143 144 144 template<typename U> NonNullPassRefPtr(const PassRefPtr<U>& o) 145 : m_ptr(o. releaseRef())145 : m_ptr(o.leakRef()) 146 146 { 147 147 ASSERT(m_ptr); … … 208 208 { 209 209 T* ptr = m_ptr; 210 m_ptr = ref. releaseRef();210 m_ptr = ref.leakRef(); 211 211 derefIfNotNull(ptr); 212 212 return *this; … … 216 216 { 217 217 T* ptr = m_ptr; 218 m_ptr = ref. releaseRef();218 m_ptr = ref.leakRef(); 219 219 derefIfNotNull(ptr); 220 220 return *this; … … 279 279 template<typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p) 280 280 { 281 return adoptRef(static_cast<T*>(p. releaseRef()));281 return adoptRef(static_cast<T*>(p.leakRef())); 282 282 } 283 283 284 284 template<typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p) 285 285 { 286 return adoptRef(const_cast<T*>(p. releaseRef()));286 return adoptRef(const_cast<T*>(p.leakRef())); 287 287 } 288 288 -
trunk/JavaScriptCore/wtf/RefPtr.h
r62674 r65130 33 33 enum PlacementNewAdoptType { PlacementNewAdopt }; 34 34 35 template 36 template 35 template<typename T> class PassRefPtr; 36 template<typename T> class NonNullPassRefPtr; 37 37 38 38 enum HashTableDeletedValueType { HashTableDeletedValue }; 39 39 40 template 40 template<typename T> class RefPtr : public FastAllocBase { 41 41 public: 42 42 ALWAYS_INLINE RefPtr() : m_ptr(0) { } 43 43 ALWAYS_INLINE RefPtr(T* ptr) : m_ptr(ptr) { refIfNotNull(ptr); } 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { T* ptr = m_ptr; refIfNotNull(ptr); } 45 // see comment in PassRefPtr.h for why this takes const reference 46 template <typename U> RefPtr(const PassRefPtr<U>&); 47 template <typename U> RefPtr(const NonNullPassRefPtr<U>&); 44 ALWAYS_INLINE RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { refIfNotNull(m_ptr); } 45 template<typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { refIfNotNull(m_ptr); } 46 47 // See comments in PassRefPtr.h for an explanation of why these takes const references. 48 template<typename U> RefPtr(const PassRefPtr<U>&); 49 template<typename U> RefPtr(const NonNullPassRefPtr<U>&); 48 50 49 51 // Special constructor for cases where we overwrite an object in place. … … 55 57 56 58 ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); } 57 58 template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { T* ptr = m_ptr; refIfNotNull(ptr); } 59 59 60 60 T* get() const { return m_ptr; } 61 61 … … 76 76 RefPtr& operator=(const PassRefPtr<T>&); 77 77 RefPtr& operator=(const NonNullPassRefPtr<T>&); 78 template 79 template 80 template 78 template<typename U> RefPtr& operator=(const RefPtr<U>&); 79 template<typename U> RefPtr& operator=(const PassRefPtr<U>&); 80 template<typename U> RefPtr& operator=(const NonNullPassRefPtr<U>&); 81 81 82 82 void swap(RefPtr&); … … 88 88 }; 89 89 90 template <typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)91 : m_ptr(o. releaseRef())92 { 93 } 94 95 template <typename T> template<typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o)96 : m_ptr(o. releaseRef())97 { 98 } 99 100 template 90 template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o) 91 : m_ptr(o.leakRef()) 92 { 93 } 94 95 template<typename T> template<typename U> inline RefPtr<T>::RefPtr(const NonNullPassRefPtr<U>& o) 96 : m_ptr(o.leakRef()) 97 { 98 } 99 100 template<typename T> inline void RefPtr<T>::clear() 101 101 { 102 102 T* ptr = m_ptr; … … 105 105 } 106 106 107 template 107 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) 108 108 { 109 109 T* optr = o.get(); … … 115 115 } 116 116 117 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)117 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o) 118 118 { 119 119 T* optr = o.get(); … … 125 125 } 126 126 127 template 127 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr) 128 128 { 129 129 refIfNotNull(optr); … … 134 134 } 135 135 136 template 137 { 138 T* ptr = m_ptr; 139 m_ptr = o. releaseRef();140 derefIfNotNull(ptr); 141 return *this; 142 } 143 144 template 145 { 146 T* ptr = m_ptr; 147 m_ptr = o. releaseRef();148 derefIfNotNull(ptr); 149 return *this; 150 } 151 152 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)153 { 154 T* ptr = m_ptr; 155 m_ptr = o. releaseRef();156 derefIfNotNull(ptr); 157 return *this; 158 } 159 160 template <typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o)161 { 162 T* ptr = m_ptr; 163 m_ptr = o. releaseRef();164 derefIfNotNull(ptr); 165 return *this; 166 } 167 168 template 136 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o) 137 { 138 T* ptr = m_ptr; 139 m_ptr = o.leakRef(); 140 derefIfNotNull(ptr); 141 return *this; 142 } 143 144 template<typename T> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<T>& o) 145 { 146 T* ptr = m_ptr; 147 m_ptr = o.leakRef(); 148 derefIfNotNull(ptr); 149 return *this; 150 } 151 152 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o) 153 { 154 T* ptr = m_ptr; 155 m_ptr = o.leakRef(); 156 derefIfNotNull(ptr); 157 return *this; 158 } 159 160 template<typename T> template<typename U> inline RefPtr<T>& RefPtr<T>::operator=(const NonNullPassRefPtr<U>& o) 161 { 162 T* ptr = m_ptr; 163 m_ptr = o.leakRef(); 164 derefIfNotNull(ptr); 165 return *this; 166 } 167 168 template<class T> inline void RefPtr<T>::swap(RefPtr<T>& o) 169 169 { 170 170 std::swap(m_ptr, o.m_ptr); 171 171 } 172 172 173 template 173 template<class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b) 174 174 { 175 175 a.swap(b); 176 176 } 177 177 178 template 178 template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b) 179 179 { 180 180 return a.get() == b.get(); 181 181 } 182 182 183 template 183 template<typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b) 184 184 { 185 185 return a.get() == b; 186 186 } 187 187 188 template 188 template<typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b) 189 189 { 190 190 return a == b.get(); 191 191 } 192 192 193 template 193 template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b) 194 194 { 195 195 return a.get() != b.get(); 196 196 } 197 197 198 template 198 template<typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b) 199 199 { 200 200 return a.get() != b; 201 201 } 202 202 203 template 203 template<typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b) 204 204 { 205 205 return a != b.get(); 206 206 } 207 207 208 template 208 template<typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p) 209 209 { 210 210 return RefPtr<T>(static_cast<T*>(p.get())); 211 211 } 212 212 213 template 213 template<typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p) 214 214 { 215 215 return RefPtr<T>(const_cast<T*>(p.get())); 216 216 } 217 217 218 template 218 template<typename T> inline T* getPtr(const RefPtr<T>& p) 219 219 { 220 220 return p.get(); -
trunk/JavaScriptCore/wtf/RetainPtr.h
r63562 r65130 1 1 /* 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.2 * Copyright (C) 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 49 49 #endif 50 50 51 template 51 template<typename T> class RetainPtr { 52 52 public: 53 53 typedef typename RemovePointer<T>::Type ValueType; … … 68 68 ~RetainPtr() { if (PtrType ptr = m_ptr) CFRelease(ptr); } 69 69 70 template <typename U> RetainPtr(const RetainPtr<U>& o) : m_ptr(o.get()) { if (PtrType ptr = m_ptr) CFRetain(ptr); }70 template<typename U> RetainPtr(const RetainPtr<U>&); 71 71 72 72 PtrType get() const { return m_ptr; } 73 74 PtrType releaseRef() { PtrType tmp = m_ptr; m_ptr = 0; return tmp; } 75 73 74 void clear(); 75 PtrType leakRef() WARN_UNUSED_RETURN; 76 76 77 PtrType operator->() const { return m_ptr; } 77 78 … … 83 84 84 85 RetainPtr& operator=(const RetainPtr&); 85 template 86 template<typename U> RetainPtr& operator=(const RetainPtr<U>&); 86 87 RetainPtr& operator=(PtrType); 87 template 88 template<typename U> RetainPtr& operator=(U*); 88 89 89 90 void adoptCF(PtrType); … … 92 93 void swap(RetainPtr&); 93 94 95 // FIXME: Remove releaseRef once we change all callers to call leakRef instead. 96 PtrType releaseRef() { return leakRef(); } 97 94 98 private: 95 99 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } … … 98 102 }; 99 103 100 template <typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o) 104 template<typename T> template<typename U> inline RetainPtr<T>::RetainPtr(const RetainPtr<U>& o) 105 : m_ptr(o.get()) 106 { 107 if (PtrType ptr = m_ptr) 108 CFRetain(ptr); 109 } 110 111 template<typename T> inline void RetainPtr<T>::clear() 112 { 113 if (PtrType ptr = m_ptr) { 114 m_ptr = 0; 115 CFRelease(ptr); 116 } 117 } 118 119 template<typename T> inline typename RetainPtr<T>::PtrType RetainPtr<T>::leakRef() 120 { 121 PtrType ptr = m_ptr; 122 m_ptr = 0; 123 return ptr; 124 } 125 126 template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<T>& o) 101 127 { 102 128 PtrType optr = o.get(); … … 110 136 } 111 137 112 template <typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o)138 template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(const RetainPtr<U>& o) 113 139 { 114 140 PtrType optr = o.get(); … … 122 148 } 123 149 124 template 125 { 126 if (optr) 127 CFRetain(optr); 128 PtrType ptr = m_ptr; 129 m_ptr = optr; 130 if (ptr) 131 CFRelease(ptr); 132 return *this; 133 } 134 135 template 136 { 137 PtrType ptr = m_ptr; 138 m_ptr = optr; 139 if (ptr) 140 CFRelease(ptr); 141 } 142 143 template 150 template<typename T> inline RetainPtr<T>& RetainPtr<T>::operator=(PtrType optr) 151 { 152 if (optr) 153 CFRetain(optr); 154 PtrType ptr = m_ptr; 155 m_ptr = optr; 156 if (ptr) 157 CFRelease(ptr); 158 return *this; 159 } 160 161 template<typename T> inline void RetainPtr<T>::adoptCF(PtrType optr) 162 { 163 PtrType ptr = m_ptr; 164 m_ptr = optr; 165 if (ptr) 166 CFRelease(ptr); 167 } 168 169 template<typename T> inline void RetainPtr<T>::adoptNS(PtrType optr) 144 170 { 145 171 adoptNSReference(optr); … … 151 177 } 152 178 153 template <typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)154 { 155 if (optr) 156 CFRetain(optr); 157 PtrType ptr = m_ptr; 158 m_ptr = optr; 159 if (ptr) 160 CFRelease(ptr); 161 return *this; 162 } 163 164 template <classT> inline void RetainPtr<T>::swap(RetainPtr<T>& o)179 template<typename T> template<typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr) 180 { 181 if (optr) 182 CFRetain(optr); 183 PtrType ptr = m_ptr; 184 m_ptr = optr; 185 if (ptr) 186 CFRelease(ptr); 187 return *this; 188 } 189 190 template<typename T> inline void RetainPtr<T>::swap(RetainPtr<T>& o) 165 191 { 166 192 std::swap(m_ptr, o.m_ptr); 167 193 } 168 194 169 template <classT> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b)195 template<typename T> inline void swap(RetainPtr<T>& a, RetainPtr<T>& b) 170 196 { 171 197 a.swap(b); 172 198 } 173 199 174 template 200 template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, const RetainPtr<U>& b) 175 201 { 176 202 return a.get() == b.get(); 177 203 } 178 204 179 template 205 template<typename T, typename U> inline bool operator==(const RetainPtr<T>& a, U* b) 180 206 { 181 207 return a.get() == b; 182 208 } 183 209 184 template 210 template<typename T, typename U> inline bool operator==(T* a, const RetainPtr<U>& b) 185 211 { 186 212 return a == b.get(); 187 213 } 188 214 189 template 215 template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, const RetainPtr<U>& b) 190 216 { 191 217 return a.get() != b.get(); 192 218 } 193 219 194 template 220 template<typename T, typename U> inline bool operator!=(const RetainPtr<T>& a, U* b) 195 221 { 196 222 return a.get() != b; 197 223 } 198 224 199 template 225 template<typename T, typename U> inline bool operator!=(T* a, const RetainPtr<U>& b) 200 226 { 201 227 return a != b.get();
Note:
See TracChangeset
for help on using the changeset viewer.