Changeset 53320 in webkit
- Timestamp:
- Jan 14, 2010 10:43:21 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSClassRef.cpp
r52978 r53320 153 153 // Use a local variable here to sidestep an RVCT compiler bug. 154 154 StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes); 155 staticValues->add(UString::Rep::create Copying(it->first->data(), it->first->size()), entry);155 staticValues->add(UString::Rep::create(it->first->data(), it->first->size()), entry); 156 156 157 157 } … … 168 168 // Use a local variable here to sidestep an RVCT compiler bug. 169 169 StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes); 170 staticFunctions->add(UString::Rep::create Copying(it->first->data(), it->first->size()), entry);170 staticFunctions->add(UString::Rep::create(it->first->data(), it->first->size()), entry); 171 171 } 172 172 -
trunk/JavaScriptCore/ChangeLog
r53239 r53320 1 2010-01-14 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Make naming & behaviour of UString[Impl] methods more consistent. 6 https://bugs.webkit.org/show_bug.cgi?id=33702 7 8 UString::create() creates a copy of the UChar* passed, but UStringImpl::create() assumes 9 that it should assume ownership of the provided buffer (with UString::createNonCopying() 10 and UStringImpl::createCopying() providing the alternate behaviours). Unify on create() 11 taking a copy of the provided buffer. For non-copying cases, use the name 'adopt', and 12 make this method take a Vector<UChar>&. For cases where non-copying construction was being 13 used, other than from a Vector<UChar>, change the code to allocate the storage along with 14 the UStringImpl using UStringImpl::createUninitialized(). (The adopt() method also more 15 closely matches that of WebCore::StringImpl). 16 17 Also, UString::createUninitialized() and UStringImpl::createUninitialized() have incompatible 18 behaviours, in that the UString form sets the provided UChar* to a null or non-null value to 19 indicate success or failure, but UStringImpl uses the returned PassRefPtr<UStringImpl> to 20 indicate when allocation has failed (potentially leaving the output Char* uninitialized). 21 This is also incompatible with WebCore::StringImpl's behaviour, in that 22 StringImpl::createUninitialized() will CRASH() if unable to allocate. Some uses of 23 createUninitialized() in JSC are unsafe, since they do not test the result for null. 24 UStringImpl's indication is preferable, since we may want a successful call to set the result 25 buffer to 0 (specifically, StringImpl returns 0 for the buffer where createUninitialized() 26 returns the empty string, which seems reasonable to catch bugs early). UString's method 27 cannot support UStringImpl's behaviour directly, since it returns an object rather than a 28 pointer. 29 - remove UString::createUninitialized(), replace with calls to UStringImpl::createUninitialized() 30 - create a UStringImpl::tryCreateUninitialized() form UStringImpl::createUninitialized(), 31 with current behaviour, make createUninitialized() crash on failure to allocate. 32 - make cases in JSC that do not check the result call createUninitialized(), and cases that do 33 check call tryCreateUninitialized(). 34 35 Rename computedHash() to existingHash(), to bring this in line wih WebCore::StringImpl. 36 37 * API/JSClassRef.cpp: 38 (OpaqueJSClassContextData::OpaqueJSClassContextData): 39 * JavaScriptCore.exp: 40 * runtime/ArrayPrototype.cpp: 41 (JSC::arrayProtoFuncToString): 42 * runtime/Identifier.cpp: 43 (JSC::CStringTranslator::translate): 44 (JSC::UCharBufferTranslator::translate): 45 * runtime/JSString.cpp: 46 (JSC::JSString::resolveRope): 47 * runtime/Lookup.cpp: 48 (JSC::HashTable::createTable): 49 * runtime/Lookup.h: 50 (JSC::HashTable::entry): 51 * runtime/StringBuilder.h: 52 (JSC::StringBuilder::release): 53 * runtime/StringConstructor.cpp: 54 (JSC::stringFromCharCodeSlowCase): 55 * runtime/StringPrototype.cpp: 56 (JSC::substituteBackreferencesSlow): 57 (JSC::stringProtoFuncToLowerCase): 58 (JSC::stringProtoFuncToUpperCase): 59 (JSC::stringProtoFuncFontsize): 60 (JSC::stringProtoFuncLink): 61 * runtime/Structure.cpp: 62 (JSC::Structure::despecifyDictionaryFunction): 63 (JSC::Structure::get): 64 (JSC::Structure::despecifyFunction): 65 (JSC::Structure::put): 66 (JSC::Structure::remove): 67 (JSC::Structure::insertIntoPropertyMapHashTable): 68 (JSC::Structure::checkConsistency): 69 * runtime/Structure.h: 70 (JSC::Structure::get): 71 * runtime/StructureTransitionTable.h: 72 (JSC::StructureTransitionTableHash::hash): 73 * runtime/UString.cpp: 74 (JSC::createRep): 75 (JSC::UString::UString): 76 (JSC::UString::spliceSubstringsWithSeparators): 77 (JSC::UString::replaceRange): 78 (JSC::UString::operator=): 79 * runtime/UString.h: 80 (JSC::UString::adopt): 81 (JSC::IdentifierRepHash::hash): 82 (JSC::makeString): 83 * runtime/UStringImpl.h: 84 (JSC::UStringImpl::adopt): 85 (JSC::UStringImpl::create): 86 (JSC::UStringImpl::createUninitialized): 87 (JSC::UStringImpl::tryCreateUninitialized): 88 (JSC::UStringImpl::existingHash): 89 1 90 2010-01-13 Kent Hansen <kent.hansen@nokia.com> 2 91 -
trunk/JavaScriptCore/JavaScriptCore.exp
r53221 r53320 106 106 __ZN3JSC11UStringImpl12sharedBufferEv 107 107 __ZN3JSC11UStringImpl6s_nullE 108 __ZN3JSC11UStringImpl7s_emptyE 108 109 __ZN3JSC11UStringImplD1Ev 109 110 __ZN3JSC11checkSyntaxEPNS_9ExecStateERKNS_10SourceCodeE … … 233 234 __ZN3JSC7Profile7excludeEPKNS_11ProfileNodeE 234 235 __ZN3JSC7Profile7forEachEMNS_11ProfileNodeEFvvE 235 __ZN3JSC7UString16createNonCopyingEPti236 236 __ZN3JSC7UString4fromEd 237 237 __ZN3JSC7UString4fromEi -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r53225 r53320 77 77 ?createInterruptedExecutionException@JSC@@YA?AVJSValue@1@PAVJSGlobalData@1@@Z 78 78 ?createLeaked@JSGlobalData@JSC@@SA?AV?$PassRefPtr@VJSGlobalData@JSC@@@WTF@@XZ 79 ?createNonCopying@UString@JSC@@SA?AV12@PA_WH@Z80 79 ?createSingleCharacterString@SmallStrings@JSC@@AAEXPAVJSGlobalData@2@E@Z 81 80 ?createStackOverflowError@JSC@@YA?AVJSValue@1@PAVExecState@1@@Z -
trunk/JavaScriptCore/runtime/ArrayPrototype.cpp
r52346 r53320 205 205 } 206 206 ASSERT(buffer.size() == totalSize); 207 unsigned finalSize = buffer.size(); 208 return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), finalSize)); 207 return jsString(exec, UString::adopt(buffer)); 209 208 } 210 209 -
trunk/JavaScriptCore/runtime/Identifier.cpp
r53151 r53320 113 113 { 114 114 size_t length = strlen(c); 115 UChar* d = static_cast<UChar*>(fastMalloc(sizeof(UChar) * length)); 115 UChar* d; 116 UString::Rep* r = UString::Rep::createUninitialized(length, d).releaseRef(); 116 117 for (size_t i = 0; i != length; i++) 117 118 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 118 119 UString::Rep* r = UString::Rep::create(d, static_cast<int>(length)).releaseRef();120 119 r->setHash(hash); 121 122 120 location = r; 123 121 } … … 178 176 static void translate(UString::Rep*& location, const UCharBuffer& buf, unsigned hash) 179 177 { 180 UChar* d = static_cast<UChar*>(fastMalloc(sizeof(UChar) * buf.length)); 178 UChar* d; 179 UString::Rep* r = UString::Rep::createUninitialized(buf.length, d).releaseRef(); 181 180 for (unsigned i = 0; i != buf.length; i++) 182 181 d[i] = buf.s[i]; 183 184 UString::Rep* r = UString::Rep::create(d, buf.length).releaseRef();185 182 r->setHash(hash); 186 187 183 location = r; 188 184 } -
trunk/JavaScriptCore/runtime/JSString.cpp
r52463 r53320 97 97 // Allocate the buffer to hold the final string, position initially points to the end. 98 98 UChar* buffer; 99 m_value = UString::createUninitialized(m_stringLength, buffer); 100 if (!buffer) { 99 if (PassRefPtr<UStringImpl> newImpl = UStringImpl::tryCreateUninitialized(m_stringLength, buffer)) 100 m_value = newImpl; 101 else { 101 102 for (unsigned i = 0; i < m_ropeLength; ++i) 102 103 m_fibers[i].deref(); -
trunk/JavaScriptCore/runtime/Lookup.cpp
r44224 r53320 35 35 for (int i = 0; values[i].key; ++i) { 36 36 UString::Rep* identifier = Identifier::add(globalData, values[i].key).releaseRef(); 37 int hashIndex = identifier-> computedHash() & compactHashSizeMask;37 int hashIndex = identifier->existingHash() & compactHashSizeMask; 38 38 HashEntry* entry = &entries[hashIndex]; 39 39 -
trunk/JavaScriptCore/runtime/Lookup.h
r48005 r53320 145 145 ASSERT(table); 146 146 147 const HashEntry* entry = &table[identifier.ustring().rep()-> computedHash() & compactHashSizeMask];147 const HashEntry* entry = &table[identifier.ustring().rep()->existingHash() & compactHashSizeMask]; 148 148 149 149 if (!entry->key()) -
trunk/JavaScriptCore/runtime/StringBuilder.h
r52346 r53320 70 70 { 71 71 buffer.shrinkToFit(); 72 size_t length = buffer.size(); 73 return UString::createNonCopying(buffer.releaseBuffer(), length); 72 return UString::adopt(buffer); 74 73 } 75 74 -
trunk/JavaScriptCore/runtime/StringConstructor.cpp
r52346 r53320 31 31 static NEVER_INLINE JSValue stringFromCharCodeSlowCase(ExecState* exec, const ArgList& args) 32 32 { 33 UChar* buf = static_cast<UChar*>(fastMalloc(args.size() * sizeof(UChar)));34 UChar* p =buf;35 ArgList::const_iterator end = args.end();36 for ( ArgList::const_iterator it = args.begin(); it != end; ++it)37 *p++ = static_cast<UChar>((*it).toUInt32(exec));38 return jsString(exec, UString::createNonCopying(buf, p - buf));33 unsigned length = args.size(); 34 UChar* buf; 35 PassRefPtr<UStringImpl> impl = UStringImpl::createUninitialized(length, buf); 36 for (unsigned i = 0; i < length; ++i) 37 buf[i] = static_cast<UChar>(args.at(i).toUInt32(exec)); 38 return jsString(exec, impl); 39 39 } 40 40 -
trunk/JavaScriptCore/runtime/StringPrototype.cpp
r52791 r53320 212 212 213 213 substitutedReplacement.shrinkToFit(); 214 unsigned size = substitutedReplacement.size(); 215 return UString::createNonCopying(substitutedReplacement.releaseBuffer(), size); 214 return UString::adopt(substitutedReplacement); 216 215 } 217 216 … … 723 722 } 724 723 if (!(ored & ~0x7f)) 725 return jsString(exec, UString:: createNonCopying(buffer.releaseBuffer(), sSize));724 return jsString(exec, UString::adopt(buffer)); 726 725 727 726 bool error; … … 733 732 return sVal; 734 733 } 735 if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) 736 return sVal; 737 return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), length)); 734 if (length == sSize) { 735 if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) 736 return sVal; 737 } else 738 buffer.resize(length); 739 return jsString(exec, UString::adopt(buffer)); 738 740 } 739 741 … … 757 759 } 758 760 if (!(ored & ~0x7f)) 759 return jsString(exec, UString:: createNonCopying(buffer.releaseBuffer(), sSize));761 return jsString(exec, UString::adopt(buffer)); 760 762 761 763 bool error; … … 767 769 return sVal; 768 770 } 769 if (length == sSize && memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) 770 return sVal; 771 return jsString(exec, UString::createNonCopying(buffer.releaseBuffer(), length)); 771 if (length == sSize) { 772 if (memcmp(buffer.data(), sData, length * sizeof(UChar)) == 0) 773 return sVal; 774 } else 775 buffer.resize(length); 776 return jsString(exec, UString::adopt(buffer)); 772 777 } 773 778 … … 853 858 unsigned bufferSize = 22 + stringSize; 854 859 UChar* buffer; 855 if (!tryFastMalloc(bufferSize * sizeof(UChar)).getValue(buffer)) 860 PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer); 861 if (!impl) 856 862 return jsUndefined(); 857 863 buffer[0] = '<'; … … 878 884 buffer[20 + stringSize] = 't'; 879 885 buffer[21 + stringSize] = '>'; 880 return jsNontrivialString(exec, UString::createNonCopying(buffer, bufferSize));886 return jsNontrivialString(exec, impl); 881 887 } 882 888 … … 901 907 unsigned bufferSize = 15 + linkTextSize + stringSize; 902 908 UChar* buffer; 903 if (!tryFastMalloc(bufferSize * sizeof(UChar)).getValue(buffer)) 909 PassRefPtr<UStringImpl> impl = UStringImpl::tryCreateUninitialized(bufferSize, buffer); 910 if (!impl) 904 911 return jsUndefined(); 905 912 buffer[0] = '<'; … … 920 927 buffer[13 + linkTextSize + stringSize] = 'a'; 921 928 buffer[14 + linkTextSize + stringSize] = '>'; 922 return jsNontrivialString(exec, UString::createNonCopying(buffer, bufferSize));929 return jsNontrivialString(exec, impl); 923 930 } 924 931 -
trunk/JavaScriptCore/runtime/Structure.cpp
r53170 r53320 304 304 ASSERT(m_propertyTable); 305 305 306 unsigned i = rep-> computedHash();306 unsigned i = rep->existingHash(); 307 307 308 308 #if DUMP_PROPERTYMAP_STATS … … 322 322 #endif 323 323 324 unsigned k = 1 | doubleHash(rep-> computedHash());324 unsigned k = 1 | doubleHash(rep->existingHash()); 325 325 326 326 while (1) { … … 687 687 return notFound; 688 688 689 unsigned i = rep-> computedHash();689 unsigned i = rep->existingHash(); 690 690 691 691 #if DUMP_PROPERTYMAP_STATS … … 707 707 #endif 708 708 709 unsigned k = 1 | doubleHash(rep-> computedHash());709 unsigned k = 1 | doubleHash(rep->existingHash()); 710 710 711 711 while (1) { … … 738 738 UString::Rep* rep = propertyName._ustring.rep(); 739 739 740 unsigned i = rep-> computedHash();740 unsigned i = rep->existingHash(); 741 741 742 742 #if DUMP_PROPERTYMAP_STATS … … 758 758 #endif 759 759 760 unsigned k = 1 | doubleHash(rep-> computedHash());760 unsigned k = 1 | doubleHash(rep->existingHash()); 761 761 762 762 while (1) { … … 807 807 // FIXME: Consider a fast case for tables with no deleted sentinels. 808 808 809 unsigned i = rep-> computedHash();809 unsigned i = rep->existingHash(); 810 810 unsigned k = 0; 811 811 bool foundDeletedElement = false; … … 830 830 831 831 if (k == 0) { 832 k = 1 | doubleHash(rep-> computedHash());832 k = 1 | doubleHash(rep->existingHash()); 833 833 #if DUMP_PROPERTYMAP_STATS 834 834 ++numCollisions; … … 910 910 911 911 // Find the thing to remove. 912 unsigned i = rep-> computedHash();912 unsigned i = rep->existingHash(); 913 913 unsigned k = 0; 914 914 unsigned entryIndex; … … 924 924 925 925 if (k == 0) { 926 k = 1 | doubleHash(rep-> computedHash());926 k = 1 | doubleHash(rep->existingHash()); 927 927 #if DUMP_PROPERTYMAP_STATS 928 928 ++numCollisions; … … 968 968 ASSERT(m_propertyTable); 969 969 970 unsigned i = entry.key-> computedHash();970 unsigned i = entry.key->existingHash(); 971 971 unsigned k = 0; 972 972 … … 981 981 982 982 if (k == 0) { 983 k = 1 | doubleHash(entry.key-> computedHash());983 k = 1 | doubleHash(entry.key->existingHash()); 984 984 #if DUMP_PROPERTYMAP_STATS 985 985 ++numCollisions; … … 1179 1179 continue; 1180 1180 ++nonEmptyEntryCount; 1181 unsigned i = rep-> computedHash();1181 unsigned i = rep->existingHash(); 1182 1182 unsigned k = 0; 1183 1183 unsigned entryIndex; … … 1188 1188 break; 1189 1189 if (k == 0) 1190 k = 1 | doubleHash(rep-> computedHash());1190 k = 1 | doubleHash(rep->existingHash()); 1191 1191 i += k; 1192 1192 } -
trunk/JavaScriptCore/runtime/Structure.h
r53170 r53320 234 234 UString::Rep* rep = propertyName._ustring.rep(); 235 235 236 unsigned i = rep-> computedHash();236 unsigned i = rep->existingHash(); 237 237 238 238 #if DUMP_PROPERTYMAP_STATS … … 251 251 #endif 252 252 253 unsigned k = 1 | WTF::doubleHash(rep-> computedHash());253 unsigned k = 1 | WTF::doubleHash(rep->existingHash()); 254 254 255 255 while (1) { -
trunk/JavaScriptCore/runtime/StructureTransitionTable.h
r48403 r53320 43 43 static unsigned hash(const Key& p) 44 44 { 45 return p.first-> computedHash();45 return p.first->existingHash(); 46 46 } 47 47 -
trunk/JavaScriptCore/runtime/UString.cpp
r52791 r53320 171 171 size_t length = strlen(c); 172 172 UChar* d; 173 PassRefPtr<UStringImpl> result = UStringImpl:: createUninitialized(length, d);173 PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d); 174 174 if (!result) 175 175 return &UString::Rep::null(); … … 189 189 190 190 UChar* d; 191 PassRefPtr<UStringImpl> result = UStringImpl:: createUninitialized(length, d);191 PassRefPtr<UStringImpl> result = UStringImpl::tryCreateUninitialized(length, d); 192 192 if (!result) 193 193 return &UString::Rep::null(); … … 213 213 m_rep = &Rep::empty(); 214 214 else 215 m_rep = Rep::createCopying(c, length); 216 } 217 218 UString UString::createNonCopying(UChar* c, int length) 219 { 220 if (length == 0) 221 return UString(&Rep::empty()); 222 else 223 return Rep::create(c, length); 215 m_rep = Rep::create(c, length); 224 216 } 225 217 … … 236 228 237 229 return UString(buffer.data(), p - buffer.data()); 238 }239 240 UString UString::createUninitialized(unsigned length, UChar*& output)241 {242 if (!length) {243 output = &sharedEmptyChar;244 return UString(&Rep::empty());245 }246 247 if (PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, output))248 return result;249 output = 0;250 return UString();251 230 } 252 231 … … 391 370 392 371 UChar* buffer; 393 if (!UStringImpl::allocChars(totalLength).getValue(buffer)) 372 PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer); 373 if (!rep) 394 374 return null(); 395 375 … … 407 387 } 408 388 409 return UString::Rep::create(buffer, totalLength);389 return rep; 410 390 } 411 391 … … 420 400 421 401 UChar* buffer; 422 if (!UStringImpl::allocChars(totalLength).getValue(buffer)) 402 PassRefPtr<Rep> rep = Rep::tryCreateUninitialized(totalLength, buffer); 403 if (!rep) 423 404 return null(); 424 405 … … 428 409 UStringImpl::copyChars(buffer + rangeStart + replacementLength, data() + rangeEnd, size() - rangeEnd); 429 410 430 return UString::Rep::create(buffer, totalLength);411 return rep; 431 412 } 432 413 … … 489 470 490 471 int l = static_cast<int>(strlen(c)); 491 UChar* d; 492 if (!UStringImpl::allocChars(l).getValue(d)) { 472 UChar* d = 0; 473 m_rep = Rep::tryCreateUninitialized(l, d); 474 if (m_rep) { 475 for (int i = 0; i < l; i++) 476 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 477 } else 493 478 makeNull(); 494 return *this;495 }496 for (int i = 0; i < l; i++)497 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend498 m_rep = Rep::create(d, l);499 479 500 480 return *this; -
trunk/JavaScriptCore/runtime/UString.h
r52463 r53320 104 104 } 105 105 106 static UString createNonCopying(UChar* c, int length); 106 template<size_t inlineCapacity> 107 static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector) 108 { 109 return Rep::adopt(vector); 110 } 111 107 112 static UString createFromUTF8(const char*); 108 static UString createUninitialized(unsigned length, UChar*& output);109 113 110 114 static UString from(int); … … 274 278 275 279 struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > { 276 static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key-> computedHash(); }277 static unsigned hash(JSC::UString::Rep* key) { return key-> computedHash(); }280 static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); } 281 static unsigned hash(JSC::UString::Rep* key) { return key->existingHash(); } 278 282 }; 279 283 … … 358 362 UChar* buffer; 359 363 unsigned length = adapter1.length() + adapter2.length(); 360 UString resultString = UString::createUninitialized(length, buffer);361 if (! buffer)362 return UString(); 363 364 UChar* result = buffer; 365 adapter1.writeTo(result); 366 result += adapter1.length(); 367 adapter2.writeTo(result); 368 369 return result String;364 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 365 if (!resultImpl) 366 return UString(); 367 368 UChar* result = buffer; 369 adapter1.writeTo(result); 370 result += adapter1.length(); 371 adapter2.writeTo(result); 372 373 return resultImpl; 370 374 } 371 375 … … 379 383 UChar* buffer; 380 384 unsigned length = adapter1.length() + adapter2.length() + adapter3.length(); 381 UString resultString = UString::createUninitialized(length, buffer);382 if (! buffer)385 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 386 if (!resultImpl) 383 387 return UString(); 384 388 … … 390 394 adapter3.writeTo(result); 391 395 392 return result String;396 return resultImpl; 393 397 } 394 398 … … 403 407 UChar* buffer; 404 408 unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length(); 405 UString resultString = UString::createUninitialized(length, buffer);406 if (! buffer)409 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 410 if (!resultImpl) 407 411 return UString(); 408 412 … … 416 420 adapter4.writeTo(result); 417 421 418 return result String;422 return resultImpl; 419 423 } 420 424 … … 430 434 UChar* buffer; 431 435 unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length(); 432 UString resultString = UString::createUninitialized(length, buffer);433 if (! buffer)436 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 437 if (!resultImpl) 434 438 return UString(); 435 439 … … 445 449 adapter5.writeTo(result); 446 450 447 return result String;451 return resultImpl; 448 452 } 449 453 … … 460 464 UChar* buffer; 461 465 unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length(); 462 UString resultString = UString::createUninitialized(length, buffer);463 if (! buffer)466 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 467 if (!resultImpl) 464 468 return UString(); 465 469 … … 477 481 adapter6.writeTo(result); 478 482 479 return result String;483 return resultImpl; 480 484 } 481 485 … … 493 497 UChar* buffer; 494 498 unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length(); 495 UString resultString = UString::createUninitialized(length, buffer);496 if (! buffer)499 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 500 if (!resultImpl) 497 501 return UString(); 498 502 … … 512 516 adapter7.writeTo(result); 513 517 514 return result String;518 return resultImpl; 515 519 } 516 520 … … 529 533 UChar* buffer; 530 534 unsigned length = adapter1.length() + adapter2.length() + adapter3.length() + adapter4.length() + adapter5.length() + adapter6.length() + adapter7.length() + adapter8.length(); 531 UString resultString = UString::createUninitialized(length, buffer);532 if (! buffer)535 PassRefPtr<UStringImpl> resultImpl = UStringImpl::tryCreateUninitialized(length, buffer); 536 if (!resultImpl) 533 537 return UString(); 534 538 … … 550 554 adapter8.writeTo(result); 551 555 552 return result String;556 return resultImpl; 553 557 } 554 558 -
trunk/JavaScriptCore/runtime/UStringImpl.h
r53221 r53320 32 32 #include <wtf/PossiblyNull.h> 33 33 #include <wtf/StringHashFunctions.h> 34 #include <wtf/Vector.h> 34 35 #include <wtf/unicode/Unicode.h> 35 36 … … 84 85 class UStringImpl : Noncopyable { 85 86 public: 86 static PassRefPtr<UStringImpl> create(UChar* buffer, int length) 87 { 88 return adoptRef(new UStringImpl(buffer, length, BufferOwned)); 89 } 90 91 static PassRefPtr<UStringImpl> createCopying(const UChar* buffer, int length) 87 template<size_t inlineCapacity> 88 static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector) 89 { 90 if (unsigned length = vector.size()) 91 return adoptRef(new UStringImpl(vector.releaseBuffer(), length, BufferOwned)); 92 return &empty(); 93 } 94 95 static PassRefPtr<UStringImpl> create(const UChar* buffer, int length) 92 96 { 93 97 UChar* newBuffer; … … 112 116 static PassRefPtr<UStringImpl> createUninitialized(unsigned length, UChar*& output) 113 117 { 114 ASSERT(length); 118 if (!length) { 119 output = 0; 120 return &empty(); 121 } 122 123 if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar))) 124 CRASH(); 125 UStringImpl* resultImpl = static_cast<UStringImpl*>(fastMalloc(sizeof(UChar) * length + sizeof(UStringImpl))); 126 output = reinterpret_cast<UChar*>(resultImpl + 1); 127 return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal)); 128 } 129 130 static PassRefPtr<UStringImpl> tryCreateUninitialized(unsigned length, UChar*& output) 131 { 132 if (!length) { 133 output = 0; 134 return &empty(); 135 } 136 115 137 if (length > ((std::numeric_limits<size_t>::max() - sizeof(UStringImpl)) / sizeof(UChar))) 116 138 return 0; 117 118 139 UStringImpl* resultImpl; 119 140 if (!tryFastMalloc(sizeof(UChar) * length + sizeof(UStringImpl)).getValue(resultImpl)) 120 141 return 0; 121 122 142 output = reinterpret_cast<UChar*>(resultImpl + 1); 123 143 return adoptRef(new(resultImpl) UStringImpl(output, length, BufferInternal)); … … 139 159 } 140 160 unsigned hash() const { if (!m_hash) m_hash = computeHash(data(), m_length); return m_hash; } 141 unsigned computedHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers161 unsigned existingHash() const { ASSERT(m_hash); return m_hash; } // fast path for Identifiers 142 162 void setHash(unsigned hash) { ASSERT(hash == computeHash(data(), m_length)); m_hash = hash; } // fast path for Identifiers 143 163 bool isIdentifier() const { return m_isIdentifier; } -
trunk/WebCore/ChangeLog
r53318 r53320 1 2010-01-14 Gavin Barraclough <barraclough@apple.com> 2 3 Rubber stamped by Sam Weinig. 4 5 Make naming & behaviour of UString[Impl] methods more consistent. 6 https://bugs.webkit.org/show_bug.cgi?id=33702 7 8 WebCore change reflecting UString method name change computedHash() -> existingHash(). 9 10 * platform/text/AtomicString.cpp: 11 (WebCore::AtomicString::add): 12 (WebCore::AtomicString::find): 13 1 14 2010-01-14 Dan Bernstein <mitz@apple.com> 2 15 -
trunk/WebCore/platform/text/AtomicString.cpp
r52729 r53320 253 253 return StringImpl::empty(); 254 254 255 HashAndCharacters buffer = { string-> computedHash(), string->data(), length };255 HashAndCharacters buffer = { string->existingHash(), string->data(), length }; 256 256 pair<HashSet<StringImpl*>::iterator, bool> addResult = stringTable().add<HashAndCharacters, HashAndCharactersTranslator>(buffer); 257 257 if (!addResult.second) … … 287 287 return static_cast<AtomicStringImpl*>(StringImpl::empty()); 288 288 289 HashAndCharacters buffer = { string-> computedHash(), string->data(), length };289 HashAndCharacters buffer = { string->existingHash(), string->data(), length }; 290 290 HashSet<StringImpl*>::iterator iterator = stringTable().find<HashAndCharacters, HashAndCharactersTranslator>(buffer); 291 291 if (iterator == stringTable().end())
Note: See TracChangeset
for help on using the changeset viewer.