Changeset 47092 in webkit for trunk/JavaScriptCore/runtime/UString.cpp
- Timestamp:
- Aug 11, 2009, 11:22:41 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.cpp
r46180 r47092 69 69 static inline size_t maxUChars() { return std::numeric_limits<size_t>::max() / sizeof(UChar); } 70 70 71 static inline UChar*allocChars(size_t length)71 static inline PossiblyNull<UChar*> allocChars(size_t length) 72 72 { 73 73 ASSERT(length); 74 74 if (length > maxUChars()) 75 75 return 0; 76 return static_cast<UChar*>(tryFastMalloc(sizeof(UChar) * length));77 } 78 79 static inline UChar*reallocChars(UChar* buffer, size_t length)76 return tryFastMalloc(sizeof(UChar) * length); 77 } 78 79 static inline PossiblyNull<UChar*> reallocChars(UChar* buffer, size_t length) 80 80 { 81 81 ASSERT(length); 82 82 if (length > maxUChars()) 83 83 return 0; 84 return static_cast<UChar*>(tryFastRealloc(buffer, sizeof(UChar) * length));84 return tryFastRealloc(buffer, sizeof(UChar) * length); 85 85 } 86 86 … … 481 481 size_t newCapacity = expandedSize(requiredLength, base->preCapacity); 482 482 UChar* oldBuf = base->buf; 483 base->buf = reallocChars(base->buf, newCapacity); 484 if (!base->buf) { 483 if (!reallocChars(base->buf, newCapacity).getValue(base->buf)) { 485 484 base->buf = oldBuf; 486 485 return false; … … 513 512 size_t newCapacity = expandedSize(capacity, base->preCapacity); 514 513 UChar* oldBuf = base->buf; 515 base->buf = reallocChars(base->buf, newCapacity); 516 if (!base->buf) { 514 if (!reallocChars(base->buf, newCapacity).getValue(base->buf)) { 517 515 base->buf = oldBuf; 518 516 return false; … … 541 539 int delta = newCapacity - base->capacity - base->preCapacity; 542 540 543 UChar* newBuf = allocChars(newCapacity);544 if (! newBuf) {541 UChar* newBuf; 542 if (!allocChars(newCapacity).getValue(newBuf)) { 545 543 makeNull(); 546 544 return; … … 567 565 568 566 size_t length = strlen(c); 569 UChar* d = allocChars(length);570 if (! d)567 UChar* d; 568 if (!allocChars(length).getValue(d)) 571 569 return &UString::Rep::null(); 572 570 else { … … 657 655 // This is shared in some way that prevents us from modifying base, so we must make a whole new string. 658 656 size_t newCapacity = expandedSize(length, 0); 659 UChar* d = allocChars(newCapacity);660 if (! d)657 UChar* d; 658 if (!allocChars(newCapacity).getValue(d)) 661 659 rep = &UString::Rep::null(); 662 660 else { … … 713 711 // This is shared in some way that prevents us from modifying base, so we must make a whole new string. 714 712 size_t newCapacity = expandedSize(length, 0); 715 UChar* d = allocChars(newCapacity);716 if (! d)713 UChar* d; 714 if (!allocChars(newCapacity).getValue(d)) 717 715 rep = &UString::Rep::null(); 718 716 else { … … 801 799 // a does not qualify for append, and b does not qualify for prepend, gotta make a whole new string 802 800 size_t newCapacity = expandedSize(length, 0); 803 UChar* d = allocChars(newCapacity);804 if (! d)801 UChar* d; 802 if (!allocChars(newCapacity).getValue(d)) 805 803 return 0; 806 804 copyChars(d, a->data(), aSize); … … 1077 1075 return ""; 1078 1076 1079 UChar* buffer = allocChars(totalLength);1080 if (! buffer)1077 UChar* buffer; 1078 if (!allocChars(totalLength).getValue(buffer)) 1081 1079 return null(); 1082 1080 … … 1106 1104 return ""; 1107 1105 1108 UChar* buffer = allocChars(totalLength);1109 if (! buffer)1106 UChar* buffer; 1107 if (!allocChars(totalLength).getValue(buffer)) 1110 1108 return null(); 1111 1109 … … 1154 1152 // This is shared in some way that prevents us from modifying base, so we must make a whole new string. 1155 1153 size_t newCapacity = expandedSize(length, 0); 1156 UChar* d = allocChars(newCapacity);1157 if (! d)1154 UChar* d; 1155 if (!allocChars(newCapacity).getValue(d)) 1158 1156 makeNull(); 1159 1157 else { … … 1207 1205 // this is empty - must make a new m_rep because we don't want to pollute the shared empty one 1208 1206 size_t newCapacity = expandedSize(1, 0); 1209 UChar* d = allocChars(newCapacity);1210 if (! d)1207 UChar* d; 1208 if (!allocChars(newCapacity).getValue(d)) 1211 1209 makeNull(); 1212 1210 else { … … 1235 1233 // This is shared in some way that prevents us from modifying base, so we must make a whole new string. 1236 1234 size_t newCapacity = expandedSize(length + 1, 0); 1237 UChar* d = allocChars(newCapacity);1238 if (! d)1235 UChar* d; 1236 if (!allocChars(newCapacity).getValue(d)) 1239 1237 makeNull(); 1240 1238 else { … … 1314 1312 m_rep->len = l; 1315 1313 } else { 1316 d = allocChars(l); 1317 if (!d) { 1314 if (!allocChars(l).getValue(d)) { 1318 1315 makeNull(); 1319 1316 return *this;
Note:
See TracChangeset
for help on using the changeset viewer.