Changeset 11684 in webkit for trunk/JavaScriptCore
- Timestamp:
- Dec 20, 2005, 12:12:50 PM (19 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r11682 r11684 1 2005-12-19 Maciej Stachowiak <[email protected]> 2 3 Reviewed by Darin. 4 5 - fixed a leak in the assignment operator from PassRefPtr to RefPtr 6 7 * kxmlcore/RefPtr.h: 8 (KXMLCore::RefPtr::operator=): 9 10 - fix problem with PassRefPtr that darin spotted - it lacked a copy constructor 11 and therefore was using the default one, which can lead to excess derefs 12 13 I fixed this by adding a copy constructor from non-const 14 reference, and by adding a template pass() function that you have 15 to use when raw pointer or RefPtr are passed where PassRefPtr is 16 expected. 17 18 * kjs/identifier.cpp: 19 (KJS::Identifier::add): Changed to have PassRefPtr return type and 20 pass() the results. 21 * kjs/identifier.h: 22 * kjs/property_map.cpp: 23 (KJS::PropertyMap::addSparseArrayPropertiesToReferenceList): Use pass() 24 where required. 25 * kjs/ustring.cpp: 26 (KJS::UString::UString): Use pass() as needed. 27 (KJS::UString::append): ditto 28 (KJS::UString::substr): ditto 29 * kjs/ustring.h: 30 (KJS::UString::UString): Use initializer instead of assignment 31 * kxmlcore/PassRefPtr.h: 32 (KXMLCore::PassRefPtr::PassRefPtr): Added copy constructor 33 (KXMLCore::pass): new template function to make it convenient to pass 34 a PassRefPtr 35 1 36 2005-12-19 Geoffrey Garen <[email protected]> 2 37 -
trunk/JavaScriptCore/kjs/identifier.cpp
r11661 r11684 124 124 } 125 125 126 UString::Rep *Identifier::add(const char *c)126 PassRefPtr<UString::Rep> Identifier::add(const char *c) 127 127 { 128 128 if (!c) 129 return &UString::Rep::null;129 return pass(&UString::Rep::null); 130 130 int length = strlen(c); 131 131 if (length == 0) 132 return &UString::Rep::empty;132 return pass(&UString::Rep::empty); 133 133 134 return *identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first;134 return pass(*identifierTable().insert<const char *, hash, KJS::equal, convert>(c).first); 135 135 } 136 136 … … 164 164 } 165 165 166 UString::Rep *Identifier::add(const UChar *s, int length)166 PassRefPtr<UString::Rep> Identifier::add(const UChar *s, int length) 167 167 { 168 168 if (length == 0) 169 return &UString::Rep::empty;169 return pass(&UString::Rep::empty); 170 170 171 171 UCharBuffer buf = {s, length}; 172 return *identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first;173 } 174 175 UString::Rep *Identifier::add(UString::Rep *r)172 return pass(*identifierTable().insert<UCharBuffer, hash, KJS::equal, convert>(buf).first); 173 } 174 175 PassRefPtr<UString::Rep> Identifier::add(UString::Rep *r) 176 176 { 177 177 if (r->isIdentifier) 178 return r;178 return pass(r); 179 179 180 180 if (r->len == 0) 181 return &UString::Rep::empty;181 return pass(&UString::Rep::empty); 182 182 183 183 UString::Rep *result = *identifierTable().insert(r).first; 184 184 if (result == r) 185 185 r->isIdentifier = true; 186 return result;186 return pass(result); 187 187 } 188 188 -
trunk/JavaScriptCore/kjs/identifier.h
r11661 r11684 78 78 { return equal(a._ustring.rep(), b); } 79 79 80 static UString::Rep *add(const char *);81 static UString::Rep *add(const UChar *, int length);82 static UString::Rep *add(UString::Rep *);80 static PassRefPtr<UString::Rep> add(const char *); 81 static PassRefPtr<UString::Rep> add(const UChar *, int length); 82 static PassRefPtr<UString::Rep> add(UString::Rep *); 83 83 }; 84 84 -
trunk/JavaScriptCore/kjs/property_map.cpp
r11527 r11684 615 615 UString::Rep *key = _singleEntry.key; 616 616 if (key) { 617 UString k( key);617 UString k(pass(key)); 618 618 bool fitsInUInt32; 619 619 k.toUInt32(&fitsInUInt32); 620 620 if (fitsInUInt32) 621 list.append(Reference(base, Identifier( key)));621 list.append(Reference(base, Identifier(pass(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( key);632 UString k(pass(key)); 633 633 bool fitsInUInt32; 634 634 k.toUInt32(&fitsInUInt32); 635 635 if (fitsInUInt32) 636 list.append(Reference(base, Identifier( key)));636 list.append(Reference(base, Identifier(pass(key)))); 637 637 } 638 638 } -
trunk/JavaScriptCore/kjs/ustring.cpp
r11638 r11684 200 200 r->usedPreCapacity = 0; 201 201 r->preCapacity = 0; 202 202 203 // steal the single reference this Rep was created with 203 204 return PassRefPtr<Rep>::adopt(r); … … 229 230 r->usedPreCapacity = 0; 230 231 r->preCapacity = 0; 232 231 233 // steal the single reference this Rep was created with 232 234 return PassRefPtr<Rep>::adopt(r); … … 458 460 x.expandCapacity(aOffset + length); 459 461 memcpy(const_cast<UChar *>(a.data() + aSize), b.data(), bSize * sizeof(UChar)); 460 m_rep = Rep::create( a.m_rep, 0, length);462 m_rep = Rep::create(pass(a.m_rep), 0, length); 461 463 } else if (-bOffset == b.usedPreCapacity() && 4 * bSize >= aSize) { 462 464 // - b reaches the beginning of its buffer so it qualifies for shared prepend … … 466 468 y.expandPreCapacity(-bOffset + aSize); 467 469 memcpy(const_cast<UChar *>(b.data() - aSize), a.data(), aSize * sizeof(UChar)); 468 m_rep = Rep::create( b.m_rep, -aSize, length);470 m_rep = Rep::create(pass(b.m_rep), -aSize, length); 469 471 } else { 470 472 // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string … … 684 686 expandCapacity(thisOffset + length); 685 687 memcpy(const_cast<UChar *>(data() + thisSize), t.data(), tSize * sizeof(UChar)); 686 m_rep = Rep::create( m_rep, 0, length);688 m_rep = Rep::create(pass(m_rep), 0, length); 687 689 } else { 688 690 // this is shared with someone using more capacity, gotta make a whole new string … … 725 727 for (int i = 0; i < tSize; ++i) 726 728 d[thisSize+i] = t[i]; 727 m_rep = Rep::create( m_rep, 0, length);729 m_rep = Rep::create(pass(m_rep), 0, length); 728 730 } else { 729 731 // this is shared with someone using more capacity, gotta make a whole new string … … 765 767 UChar *d = const_cast<UChar *>(data()); 766 768 d[length] = c; 767 m_rep = Rep::create( m_rep, 0, length + 1);769 m_rep = Rep::create(pass(m_rep), 0, length + 1); 768 770 } else { 769 771 // this is shared with someone using more capacity, gotta make a whole new string … … 1121 1123 return *this; 1122 1124 1123 return UString(Rep::create( m_rep, pos, len));1125 return UString(Rep::create(pass(m_rep), pos, len)); 1124 1126 } 1125 1127 -
trunk/JavaScriptCore/kxmlcore/PassRefPtr.h
r11670 r11684 45 45 PassRefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 46 46 PassRefPtr(const RefPtr<T>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); } 47 PassRefPtr(PassRefPtr& o) : m_ptr(o.release()) {} 47 48 48 49 ~PassRefPtr() { if (T *ptr = m_ptr) ptr->deref(); } … … 84 85 return *this; 85 86 } 86 87 87 88 template<typename U> 88 89 operator PassRefPtr_Ref<U>() … … 191 192 } 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); 202 } 203 193 204 } // namespace KXMLCore 194 205 … … 196 207 using KXMLCore::static_pointer_cast; 197 208 using KXMLCore::const_pointer_cast; 209 using KXMLCore::pass; 198 210 199 211 #endif // KXMLCORE_PASS_REF_PTR_H -
trunk/JavaScriptCore/kxmlcore/RefPtr.h
r11670 r11684 91 91 template <class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o) 92 92 { 93 T *optr = o.release();94 if (optr)95 optr->ref();96 93 if (T *ptr = m_ptr) 97 94 ptr->deref(); 98 m_ptr = o ptr;95 m_ptr = o.release(); 99 96 return *this; 100 97 }
Note:
See TracChangeset
for help on using the changeset viewer.