Changeset 11763 in webkit for trunk/JavaScriptCore
- Timestamp:
- Dec 25, 2005, 1:22:35 AM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r11762 r11763 1 2005-12-24 Maciej Stachowiak <[email protected]> 2 3 Reviewed by Eric and Dave Hyatt. 4 5 - make even const PassRefPtrs give transfer of ownership semantics 6 http://bugzilla.opendarwin.org/show_bug.cgi?id=6238 7 8 This is a somewhat cheesy change. Having to use PassRefPtr_Ref creates ambiguities 9 in assignment and copy construction. And this makes life way easier and removes 10 the need for pass(). It is not really correct, but we pretty much never need a real 11 const PassRefPtr, and this takes care of things for PassRefPtr temporaries. 12 13 * kjs/identifier.cpp: 14 (KJS::Identifier::add): No more need for pass() 15 * kjs/property_map.cpp: 16 (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): No more need for pass() 17 * kjs/ustring.cpp: 18 (KJS::UString::Rep::create): Use adoptRef 19 (KJS::UString::UString): No more need for pass 20 (KJS::UString::append): No more need for pass 21 (KJS::UString::substr): No more need for pass 22 * kxmlcore/PassRefPtr.h: made m_ptr mutable (ugh) 23 (KXMLCore::PassRefPtr::PassRefPtr): Take a const PassRefPtr reference 24 (KXMLCore::PassRefPtr::release): Made this a const method (ugh) 25 (KXMLCore::PassRefPtr::operator=): clean up appropriately 26 (KXMLCore::adoptRef): Added this to use instead of PassRefPtr<T>::adopt, I think 27 it makes the behavior more clear and it is less verbose. 28 (KXMLCore::static_pointer_cast): use adoptRef 29 (KXMLCore::const_pointer_cast): use adoptRef 30 * kxmlcore/RefPtr.h: 31 (KXMLCore::RefPtr::RefPtr): take const PassRefPtr& 32 (KXMLCore::PassRefPtr::operator=): take const PassRefPtr& 33 1 34 2005-12-25 Eric Seidel <[email protected]> 2 35 -
trunk/JavaScriptCore/kjs/identifier.cpp
r11739 r11763 130 130 { 131 131 if (!c) 132 return pass(&UString::Rep::null);132 return &UString::Rep::null; 133 133 int length = strlen(c); 134 134 if (length == 0) 135 return pass(&UString::Rep::empty);135 return &UString::Rep::empty; 136 136 137 return pass(*identifierTable().insert<const char *, CStringTranslator>(c).first);137 return *identifierTable().insert<const char *, CStringTranslator>(c).first; 138 138 } 139 139 … … 173 173 { 174 174 if (length == 0) 175 return pass(&UString::Rep::empty);175 return &UString::Rep::empty; 176 176 177 177 UCharBuffer buf = {s, length}; 178 return pass(*identifierTable().insert<UCharBuffer, UCharBufferTranslator>(buf).first);178 return *identifierTable().insert<UCharBuffer, UCharBufferTranslator>(buf).first; 179 179 } 180 180 … … 182 182 { 183 183 if (r->isIdentifier) 184 return pass(r);184 return r; 185 185 186 186 if (r->len == 0) 187 return pass(&UString::Rep::empty);187 return &UString::Rep::empty; 188 188 189 189 UString::Rep *result = *identifierTable().insert(r).first; 190 190 if (result == r) 191 191 r->isIdentifier = true; 192 return pass(result);192 return result; 193 193 } 194 194 -
trunk/JavaScriptCore/kjs/property_map.cpp
r11684 r11763 615 615 UString::Rep *key = _singleEntry.key; 616 616 if (key) { 617 UString k( pass(key));617 UString k(key); 618 618 bool fitsInUInt32; 619 619 k.toUInt32(&fitsInUInt32); 620 620 if (fitsInUInt32) 621 list.append(Reference(base, Identifier( pass(key))));621 list.append(Reference(base, Identifier(key))); 622 622 } 623 623 #endif … … 630 630 UString::Rep *key = entries[i].key; 631 631 if (key && key != &UString::Rep::null) { 632 UString k( pass(key));632 UString k(key); 633 633 bool fitsInUInt32; 634 634 k.toUInt32(&fitsInUInt32); 635 635 if (fitsInUInt32) 636 list.append(Reference(base, Identifier( pass(key))));636 list.append(Reference(base, Identifier(key))); 637 637 } 638 638 } -
trunk/JavaScriptCore/kjs/ustring.cpp
r11684 r11763 202 202 203 203 // steal the single reference this Rep was created with 204 return PassRefPtr<Rep>::adopt(r);204 return adoptRef(r); 205 205 } 206 206 … … 232 232 233 233 // steal the single reference this Rep was created with 234 return PassRefPtr<Rep>::adopt(r);234 return adoptRef(r); 235 235 } 236 236 … … 460 460 x.expandCapacity(aOffset + length); 461 461 memcpy(const_cast<UChar *>(a.data() + aSize), b.data(), bSize * sizeof(UChar)); 462 m_rep = Rep::create( pass(a.m_rep), 0, length);462 m_rep = Rep::create(a.m_rep, 0, length); 463 463 } else if (-bOffset == b.usedPreCapacity() && 4 * bSize >= aSize) { 464 464 // - b reaches the beginning of its buffer so it qualifies for shared prepend … … 468 468 y.expandPreCapacity(-bOffset + aSize); 469 469 memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar)); 470 m_rep = Rep::create( pass(b.m_rep), -aSize, length);470 m_rep = Rep::create(b.m_rep, -aSize, length); 471 471 } else { 472 472 // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string … … 686 686 expandCapacity(thisOffset + length); 687 687 memcpy(const_cast<UChar *>(data() + thisSize), t.data(), tSize * sizeof(UChar)); 688 m_rep = Rep::create( pass(m_rep), 0, length);688 m_rep = Rep::create(m_rep, 0, length); 689 689 } else { 690 690 // this is shared with someone using more capacity, gotta make a whole new string … … 727 727 for (int i = 0; i < tSize; ++i) 728 728 d[thisSize+i] = t[i]; 729 m_rep = Rep::create( pass(m_rep), 0, length);729 m_rep = Rep::create(m_rep, 0, length); 730 730 } else { 731 731 // this is shared with someone using more capacity, gotta make a whole new string … … 767 767 UChar *d = const_cast<UChar *>(data()); 768 768 d[length] = c; 769 m_rep = Rep::create( pass(m_rep), 0, length + 1);769 m_rep = Rep::create(m_rep, 0, length + 1); 770 770 } else { 771 771 // this is shared with someone using more capacity, gotta make a whole new string … … 1123 1123 return *this; 1124 1124 1125 return UString(Rep::create( pass(m_rep), pos, len));1125 return UString(Rep::create(m_rep, pos, len)); 1126 1126 } 1127 1127 -
trunk/JavaScriptCore/kjs/ustring.h
r11473 r11763 463 463 464 464 Rep *rep() const { return m_rep.get(); } 465 UString(PassRefPtr<Rep> r) { m_rep = r;}465 UString(PassRefPtr<Rep> r) : m_rep(r) { } 466 466 467 467 void copyForWriting(); -
trunk/JavaScriptCore/kxmlcore/PassRefPtr.h
r11727 r11763 28 28 template<typename T> class RefPtr; 29 29 template<typename T> class PassRefPtr; 30 31 // PassRefPtr_Ref class is a helper to allow proper passing of PassRefPtr by value but not by const 32 // reference 33 template<typename T> 34 struct PassRefPtr_Ref 35 { 36 T* m_ptr; 37 explicit PassRefPtr_Ref(T* p) : m_ptr(p) {} 38 }; 30 template <typename T> PassRefPtr<T> adoptRef(T *p); 39 31 40 32 template<typename T> … … 44 36 PassRefPtr() : m_ptr(0) {} 45 37 PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 46 PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {} 47 template <typename U> PassRefPtr(PassRefPtr<U>& o) : m_ptr(o.release()) { } 38 // It somewhat breaks the type system to allow transfer of ownership out of 39 // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr 40 // temporaries, and we don't really have a need to use real const PassRefPtrs 41 // anyway. 42 PassRefPtr(const PassRefPtr& o) : m_ptr(o.release()) {} 43 template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.release()) { } 48 44 49 45 ~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); } … … 54 50 T *get() const { return m_ptr; } 55 51 56 T *release() { T *tmp = m_ptr; m_ptr = 0; return tmp; }52 T *release() const { T *tmp = m_ptr; m_ptr = 0; return tmp; } 57 53 58 template <typename U> static PassRefPtr<T> adopt(U* ptr)59 {60 PassRefPtr result((PassRefPtr_Ref<T>(ptr)));61 return result;62 }63 64 54 T& operator*() const { return *m_ptr; } 65 55 T *operator->() const { return m_ptr; } … … 72 62 73 63 PassRefPtr& operator=(T *); 74 PassRefPtr& operator=( PassRefPtr&);75 template <typename U> PassRefPtr& operator=( PassRefPtr<U>&);64 PassRefPtr& operator=(const PassRefPtr&); 65 template <typename U> PassRefPtr& operator=(const PassRefPtr<U>&); 76 66 template <typename U> PassRefPtr& operator=(const RefPtr<U>&); 77 67 78 PassRefPtr(PassRefPtr_Ref<T> ref) : m_ptr(ref.m_ptr) { } 79 80 PassRefPtr& operator=(PassRefPtr_Ref<T> ref) 81 { 82 if (m_ptr) 83 m_ptr->deref(); 84 m_ptr = ref.m_ptr; 85 return *this; 86 } 87 88 template <typename U> operator PassRefPtr_Ref<U>() { return PassRefPtr_Ref<U>(release()); } 89 template <typename U> operator PassRefPtr<U>() { return PassRefPtr_Ref<U>(release()); } 90 68 friend PassRefPtr adoptRef<T>(T *); 91 69 private: 92 T *m_ptr; 70 // adopting constructor 71 PassRefPtr(T *ptr, bool) : m_ptr(ptr) {} 72 mutable T *m_ptr; 93 73 }; 94 74 … … 114 94 } 115 95 116 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=( PassRefPtr<T>& ref)96 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const PassRefPtr<T>& ref) 117 97 { 118 98 T *optr = ref.release(); … … 123 103 } 124 104 125 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=( PassRefPtr<U>& ref)105 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const PassRefPtr<U>& ref) 126 106 { 127 107 T *optr = ref.release(); … … 182 162 } 183 163 164 template <typename T> inline PassRefPtr<T> adoptRef(T *p) 165 { 166 return PassRefPtr<T>(p, true); 167 } 168 184 169 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p) 185 170 { 186 return PassRefPtr<T>::adopt(static_cast<T *>(p.release()));171 return adoptRef(static_cast<T *>(p.release())); 187 172 } 188 173 189 174 template <typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p) 190 175 { 191 return PassRefPtr<T>::adopt(const_cast<T *>(p.release())); 192 } 193 194 template <typename T> inline PassRefPtr<T> pass(T *ptr) 195 { 196 return PassRefPtr<T>(ptr); 197 } 198 199 template <typename T> inline PassRefPtr<T> pass(const RefPtr<T>& ptr) 200 { 201 return PassRefPtr<T>(ptr); 176 return adoptRef(const_cast<T *>(p.release())); 202 177 } 203 178 … … 205 180 206 181 using KXMLCore::PassRefPtr; 182 using KXMLCore::adoptRef; 207 183 using KXMLCore::static_pointer_cast; 208 184 using KXMLCore::const_pointer_cast; 209 using KXMLCore::pass;210 185 211 186 #endif // KXMLCORE_PASS_REF_PTR_H -
trunk/JavaScriptCore/kxmlcore/RefPtr.h
r11747 r11763 29 29 30 30 template <typename T> class PassRefPtr; 31 template <typename T> class PassRefPtr_Ref;32 31 33 32 template <typename T> class RefPtr … … 37 36 RefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 38 37 RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->ref(); } 39 template <typename U> RefPtr(PassRefPtr<U>&);40 template <typename U> RefPtr( PassRefPtr_Ref<U>);38 // see comment in PassRefPtr.h for why this takes const reference 39 template <typename U> RefPtr(const PassRefPtr<U>&); 41 40 42 41 ~RefPtr() { if (T *ptr = m_ptr) ptr->deref(); } … … 57 56 RefPtr& operator=(const RefPtr&); 58 57 RefPtr& operator=(T *); 59 RefPtr& operator=(PassRefPtr<T>&); 60 RefPtr& operator=(PassRefPtr_Ref<T>); 58 RefPtr& operator=(const PassRefPtr<T>&); 61 59 template <typename U> RefPtr& operator=(const RefPtr<U>&); 62 template <typename U> RefPtr& operator=(PassRefPtr<U>&); 63 template <typename U> RefPtr& operator=(PassRefPtr_Ref<U>); 60 template <typename U> RefPtr& operator=(const PassRefPtr<U>&); 64 61 65 62 void swap(RefPtr&); … … 69 66 }; 70 67 71 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr_Ref<U> ref) 72 : m_ptr(ref.m_ptr) 73 { 74 } 75 76 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr<U>& o) 68 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o) 77 69 : m_ptr(o.release()) 78 70 { … … 111 103 } 112 104 113 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<U> ref) 114 { 115 if (m_ptr) 116 m_ptr->deref(); 117 m_ptr = ref.m_ptr; 118 return *this; 119 } 120 121 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o) 105 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o) 122 106 { 123 107 if (m_ptr) … … 127 111 } 128 112 129 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref) 130 { 131 if (m_ptr) 132 m_ptr->deref(); 133 m_ptr = ref.m_ptr; 134 return *this; 135 } 136 137 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<U>& o) 113 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o) 138 114 { 139 115 if (m_ptr)
Note:
See TracChangeset
for help on using the changeset viewer.