Changeset 9009 in webkit for trunk/JavaScriptCore/kjs/ustring.cpp
- Timestamp:
- Apr 14, 2005, 6:26:26 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ustring.cpp
r7798 r9009 36 36 #endif 37 37 38 #include "fast_malloc.h" 38 39 #include "ustring.h" 39 40 #include "operations.h" … … 45 46 46 47 #include <unicode/uchar.h> 47 48 // malloc_good_size is not prototyped anywhere!49 extern "C" {50 size_t malloc_good_size(size_t size);51 }52 48 53 49 #endif … … 194 190 return callerBetterNotModifyThis; 195 191 } 192 } 193 194 UString::Rep *UString::Rep::createCopying(const UChar *d, int l) 195 { 196 int sizeInBytes = l * sizeof(UChar); 197 UChar *copyD = static_cast<UChar *>(kjs_fast_malloc(sizeInBytes)); 198 memcpy(copyD, d, sizeInBytes); 199 200 return create(copyD, l); 196 201 } 197 202 … … 249 254 baseString->deref(); 250 255 } else { 251 free(buf);256 kjs_fast_free(buf); 252 257 } 253 258 delete this; … … 331 336 { 332 337 int s = (size * 11 / 10) + 1 + otherSize; 333 #if APPLE_CHANGES334 s = malloc_good_size(s * sizeof(UChar)) / sizeof(UChar);335 #endif336 338 return s; 337 339 } … … 353 355 if (requiredLength > r->capacity) { 354 356 int newCapacity = expandedSize(requiredLength, r->preCapacity); 355 r->buf = static_cast<UChar *>( realloc(r->buf, newCapacity * sizeof(UChar)));357 r->buf = static_cast<UChar *>(kjs_fast_realloc(r->buf, newCapacity * sizeof(UChar))); 356 358 r->capacity = newCapacity - r->preCapacity; 357 359 } … … 369 371 int delta = newCapacity - r->capacity - r->preCapacity; 370 372 371 UChar *newBuf = static_cast<UChar *>( malloc(newCapacity * sizeof(UChar)));373 UChar *newBuf = static_cast<UChar *>(kjs_fast_malloc(newCapacity * sizeof(UChar))); 372 374 memcpy(newBuf + delta, r->buf, (r->capacity + r->preCapacity) * sizeof(UChar)); 373 free(r->buf);375 kjs_fast_free(r->buf); 374 376 r->buf = newBuf; 375 377 … … 389 391 UString::UString(char c) 390 392 { 391 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar)));393 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar))); 392 394 d[0] = c; 393 395 rep = Rep::create(d, 1); … … 405 407 return; 406 408 } 407 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * length));409 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * length)); 408 410 for (int i = 0; i < length; i++) 409 411 d[i].uc = c[i]; … … 417 419 return; 418 420 } 419 UChar *d = static_cast<UChar *>(malloc(sizeof(UChar) *length)); 420 memcpy(d, c, length * sizeof(UChar)); 421 rep = Rep::create(d, length); 421 rep = Rep::createCopying(c, length); 422 422 } 423 423 … … 428 428 return; 429 429 } 430 UChar *d;431 430 if (copy) { 432 d = static_cast<UChar *>(malloc(sizeof(UChar) * length)); 433 memcpy(d, c, length * sizeof(UChar)); 434 } else 435 d = c; 436 rep = Rep::create(d, length); 431 rep = Rep::createCopying(c, length); 432 } else { 433 rep = Rep::create(c, length); 434 } 437 435 } 438 436 … … 474 472 // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string 475 473 int newCapacity = expandedSize(length, 0); 476 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * newCapacity));474 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * newCapacity)); 477 475 memcpy(d, a.data(), aSize * sizeof(UChar)); 478 476 memcpy(d + aSize, b.data(), bSize * sizeof(UChar)); … … 620 618 } 621 619 622 UChar *buffer = static_cast<UChar *>( malloc(totalLength * sizeof(UChar)));620 UChar *buffer = static_cast<UChar *>(kjs_fast_malloc(totalLength * sizeof(UChar))); 623 621 624 622 int maxCount = MAX(rangeCount, separatorCount); … … 673 671 // this is shared with someone using more capacity, gotta make a whole new string 674 672 int newCapacity = expandedSize(length, 0); 675 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * newCapacity));673 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * newCapacity)); 676 674 memcpy(d, data(), thisSize * sizeof(UChar)); 677 675 memcpy(const_cast<UChar *>(d + thisSize), t.data(), tSize * sizeof(UChar)); … … 717 715 // this is shared with someone using more capacity, gotta make a whole new string 718 716 int newCapacity = expandedSize(length, 0); 719 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * newCapacity));717 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * newCapacity)); 720 718 memcpy(d, data(), thisSize * sizeof(UChar)); 721 719 for (int i = 0; i < tSize; ++i) … … 738 736 // this is empty - must make a new rep because we don't want to pollute the shared empty one 739 737 int newCapacity = expandedSize(1, 0); 740 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * newCapacity));738 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * newCapacity)); 741 739 d[0] = c; 742 740 release(); … … 761 759 // this is shared with someone using more capacity, gotta make a whole new string 762 760 int newCapacity = expandedSize((length + 1), 0); 763 UChar *d = static_cast<UChar *>( malloc(sizeof(UChar) * newCapacity));761 UChar *d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * newCapacity)); 764 762 memcpy(d, data(), length * sizeof(UChar)); 765 763 d[length] = c; … … 823 821 } else { 824 822 release(); 825 d = static_cast<UChar *>( malloc(sizeof(UChar) * l));823 d = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * l)); 826 824 rep = Rep::create(d, l); 827 825 } … … 1138 1136 if (rep->rc > 1 || rep->baseString) { 1139 1137 int l = size(); 1140 UChar *n = static_cast<UChar *>( malloc(sizeof(UChar) * l));1138 UChar *n = static_cast<UChar *>(kjs_fast_malloc(sizeof(UChar) * l)); 1141 1139 memcpy(n, data(), l * sizeof(UChar)); 1142 1140 release();
Note:
See TracChangeset
for help on using the changeset viewer.