Changeset 54789 in webkit
- Timestamp:
- Feb 15, 2010 1:03:45 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r54788 r54789 1 2010-02-15 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Geoff Garen. 4 5 Bug 34952 - String lengths in UString should be unsigned. 6 This matches WebCore::StringImpl, and better unifies behaviour throughout JSC. 7 8 * JavaScriptCore.exp: 9 * bytecode/EvalCodeCache.h: 10 * runtime/Identifier.cpp: 11 (JSC::Identifier::equal): 12 * runtime/Identifier.h: 13 * runtime/JSGlobalObjectFunctions.cpp: 14 (JSC::globalFuncEscape): 15 * runtime/JSONObject.cpp: 16 (JSC::gap): 17 (JSC::Stringifier::indent): 18 * runtime/NumberPrototype.cpp: 19 (JSC::numberProtoFuncToFixed): 20 (JSC::numberProtoFuncToPrecision): 21 * runtime/RegExp.cpp: 22 (JSC::RegExp::match): 23 * runtime/StringPrototype.cpp: 24 (JSC::substituteBackreferencesSlow): 25 (JSC::stringProtoFuncReplace): 26 (JSC::stringProtoFuncSplit): 27 (JSC::trimString): 28 * runtime/UString.cpp: 29 (JSC::UString::UString): 30 (JSC::UString::from): 31 (JSC::UString::getCString): 32 (JSC::UString::ascii): 33 (JSC::UString::operator[]): 34 (JSC::UString::toStrictUInt32): 35 (JSC::UString::find): 36 (JSC::UString::rfind): 37 (JSC::UString::substr): 38 (JSC::operator<): 39 (JSC::operator>): 40 (JSC::compare): 41 (JSC::equal): 42 (JSC::UString::UTF8String): 43 * runtime/UString.h: 44 (JSC::UString::size): 45 (JSC::operator==): 46 * runtime/UStringImpl.cpp: 47 (JSC::UStringImpl::create): 48 * runtime/UStringImpl.h: 49 (JSC::UStringImpl::create): 50 (JSC::UStringImpl::size): 51 (JSC::UStringImpl::computeHash): 52 (JSC::UStringImpl::UStringImpl): 53 1 54 2010-02-15 Gavin Barraclough <barraclough@apple.com> 2 55 -
trunk/JavaScriptCore/JavaScriptCore.exp
r54672 r54789 241 241 __ZN3JSC7UString9s_nullRepE 242 242 __ZN3JSC7UStringC1EPKc 243 __ZN3JSC7UStringC1EPKt i243 __ZN3JSC7UStringC1EPKtj 244 244 __ZN3JSC8Debugger23recompileAllJSFunctionsEPNS_12JSGlobalDataE 245 245 __ZN3JSC8Debugger6attachEPNS_14JSGlobalObjectE … … 394 394 __ZNK3JSC7UString5asciiEv 395 395 __ZNK3JSC7UString6is8BitEv 396 __ZNK3JSC7UString6substrE ii396 __ZNK3JSC7UString6substrEjj 397 397 __ZNK3JSC7UString8toUInt32EPb 398 398 __ZNK3JSC7UString8toUInt32EPbb -
trunk/JavaScriptCore/bytecode/CodeBlock.cpp
r52028 r54789 50 50 { 51 51 UString result = str; 52 intpos = 0;53 while ((pos = result.find('\"', pos)) >= 0) {52 unsigned pos = 0; 53 while ((pos = result.find('\"', pos)) != UString::NotFound) { 54 54 result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1)); 55 55 pos += 4; -
trunk/JavaScriptCore/bytecode/EvalCodeCache.h
r48662 r54789 66 66 67 67 private: 68 static const intmaxCacheableSourceLength = 256;68 static const unsigned maxCacheableSourceLength = 256; 69 69 static const int maxCacheEntries = 64; 70 70 -
trunk/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r52028 r54789 77 77 static void substitute(UString& string, const UString& substring) 78 78 { 79 intposition = string.find("%s");80 ASSERT(position != -1);79 unsigned position = string.find("%s"); 80 ASSERT(position != UString::NotFound); 81 81 string = makeString(string.substr(0, position), substring, string.substr(position + 2)); 82 82 } -
trunk/JavaScriptCore/runtime/Identifier.cpp
r54510 r54789 88 88 } 89 89 90 bool Identifier::equal(const UString::Rep* r, const UChar* s, intlength)90 bool Identifier::equal(const UString::Rep* r, const UChar* s, unsigned length) 91 91 { 92 92 if (r->size() != length) 93 93 return false; 94 94 const UChar* d = r->data(); 95 for ( inti = 0; i != length; ++i)95 for (unsigned i = 0; i != length; ++i) 96 96 if (d[i] != s[i]) 97 97 return false; -
trunk/JavaScriptCore/runtime/Identifier.h
r52856 r54789 77 77 78 78 static bool equal(const UString::Rep*, const char*); 79 static bool equal(const UString::Rep*, const UChar*, intlength);79 static bool equal(const UString::Rep*, const UChar*, unsigned length); 80 80 static bool equal(const UString::Rep* a, const UString::Rep* b) { return JSC::equal(a, b); } 81 81 -
trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r54571 r54789 382 382 UString str = args.at(0).toString(exec); 383 383 const UChar* c = str.data(); 384 for ( intk = 0; k < str.size(); k++, c++) {384 for (unsigned k = 0; k < str.size(); k++, c++) { 385 385 int u = c[0]; 386 386 if (u > 255) { -
trunk/JavaScriptCore/runtime/JSONObject.cpp
r54571 r54789 136 136 static inline UString gap(ExecState* exec, JSValue space) 137 137 { 138 const intmaxGapLength = 10;138 const unsigned maxGapLength = 10; 139 139 space = unwrapBoxedPrimitive(exec, space); 140 140 … … 457 457 { 458 458 // Use a single shared string, m_repeatedGap, so we don't keep allocating new ones as we indent and unindent. 459 intnewSize = m_indent.size() + m_gap.size();459 unsigned newSize = m_indent.size() + m_gap.size(); 460 460 if (newSize > m_repeatedGap.size()) 461 461 m_repeatedGap = makeString(m_repeatedGap, m_gap); -
trunk/JavaScriptCore/runtime/NumberPrototype.cpp
r54571 r54789 266 266 m = z.build(); 267 267 k = f + 1; 268 ASSERT(k == m.size());268 ASSERT(k == static_cast<int>(m.size())); 269 269 } 270 270 int kMinusf = k - f; 271 271 272 if (kMinusf < m.size())272 if (kMinusf < static_cast<int>(m.size())) 273 273 return jsString(exec, makeString(s, m.substr(0, kMinusf), ".", m.substr(kMinusf))); 274 274 return jsString(exec, makeString(s, m.substr(0, kMinusf))); … … 445 445 return jsString(exec, makeString(s, m)); 446 446 if (e >= 0) { 447 if (e + 1 < m.size())447 if (e + 1 < static_cast<int>(m.size())) 448 448 return jsString(exec, makeString(s, m.substr(0, e + 1), ".", m.substr(e + 1))); 449 449 return jsString(exec, makeString(s, m)); -
trunk/JavaScriptCore/runtime/RegExp.cpp
r53032 r54789 72 72 // NOTE: The global flag is handled on a case-by-case basis by functions like 73 73 // String::match and RegExpObject::match. 74 if (flags.find('g') != -1)74 if (flags.find('g') != UString::NotFound) 75 75 m_flagBits |= Global; 76 if (flags.find('i') != -1)76 if (flags.find('i') != UString::NotFound) 77 77 m_flagBits |= IgnoreCase; 78 if (flags.find('m') != -1)78 if (flags.find('m') != UString::NotFound) 79 79 m_flagBits |= Multiline; 80 80 … … 118 118 ovector->clear(); 119 119 120 if (sta rtOffset> s.size() || s.isNull())120 if (static_cast<unsigned>(startOffset) > s.size() || s.isNull()) 121 121 return -1; 122 122 -
trunk/JavaScriptCore/runtime/StringPrototype.cpp
r54532 r54789 151 151 // ------------------------------ Functions -------------------------- 152 152 153 static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, inti)153 static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, unsigned i) 154 154 { 155 155 Vector<UChar> substitutedReplacement; … … 207 207 offset = i + 1; 208 208 substitutedReplacement.append(source.data() + backrefStart, backrefLength); 209 } while ((i = replacement.find('$', i + 1)) != -1);209 } while ((i = replacement.find('$', i + 1)) != UString::NotFound); 210 210 211 211 if (replacement.size() - offset) … … 218 218 static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg) 219 219 { 220 inti = replacement.find('$', 0);221 if (UNLIKELY(i != -1))220 unsigned i = replacement.find('$', 0); 221 if (UNLIKELY(i != UString::NotFound)) 222 222 return substituteBackreferencesSlow(replacement, source, ovector, reg, i); 223 223 return replacement; … … 330 330 331 331 int lastIndex = 0; 332 intstartPosition = 0;332 unsigned startPosition = 0; 333 333 334 334 Vector<StringRange, 16> sourceRanges; … … 433 433 return sourceVal; 434 434 435 if ( lastIndex< source.size())435 if (static_cast<unsigned>(lastIndex) < source.size()) 436 436 sourceRanges.append(StringRange(lastIndex, source.size() - lastIndex)); 437 437 … … 442 442 443 443 UString patternString = pattern.toString(exec); 444 intmatchPos = source.find(patternString);445 446 if (matchPos == -1)444 unsigned matchPos = source.find(patternString); 445 446 if (matchPos == UString::NotFound) 447 447 return sourceVal; 448 448 … … 542 542 } 543 543 544 return jsNumber(exec, s.find(u2, pos)); 544 unsigned result = s.find(u2, pos); 545 if (result == UString::NotFound) 546 return jsNumber(exec, -1); 547 return jsNumber(exec, result); 545 548 } 546 549 … … 564 567 dpos = len; 565 568 #endif 566 return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos))); 569 570 unsigned result = s.rfind(u2, static_cast<unsigned>(dpos)); 571 if (result == UString::NotFound) 572 return jsNumber(exec, -1); 573 return jsNumber(exec, result); 567 574 } 568 575 … … 676 683 JSArray* result = constructEmptyArray(exec); 677 684 unsigned i = 0; 678 intp0 = 0;685 unsigned p0 = 0; 679 686 unsigned limit = a1.isUndefined() ? 0xFFFFFFFFU : a1.toUInt32(exec); 680 687 if (a0.inherits(&RegExpObject::info)) { … … 684 691 return result; 685 692 } 686 intpos = 0;693 unsigned pos = 0; 687 694 while (i != limit && pos < s.size()) { 688 695 Vector<int, 32> ovector; … … 692 699 int mlen = ovector[1] - ovector[0]; 693 700 pos = mpos + (mlen == 0 ? 1 : mlen); 694 if ( mpos!= p0 || mlen) {701 if (static_cast<unsigned>(mpos) != p0 || mlen) { 695 702 result->put(exec, i++, jsSubstring(exec, s, p0, mpos - p0)); 696 703 p0 = mpos + mlen; … … 714 721 result->put(exec, i++, jsSingleCharacterSubstring(exec, s, p0++)); 715 722 } else { 716 int pos; 717 while (i != limit && (pos = s.find(u2, p0)) >= 0) { 723 unsigned pos; 724 725 while (i != limit && (pos = s.find(u2, p0)) != UString::NotFound) { 718 726 result->put(exec, i++, jsSubstring(exec, s, p0, pos - p0)); 719 727 p0 = pos + u2.size(); … … 1023 1031 { 1024 1032 UString str = thisValue.toThisString(exec); 1025 intleft = 0;1033 unsigned left = 0; 1026 1034 if (trimKind & TrimLeft) { 1027 1035 while (left < str.size() && isTrimWhitespace(str[left])) 1028 1036 left++; 1029 1037 } 1030 intright = str.size();1038 unsigned right = str.size(); 1031 1039 if (trimKind & TrimRight) { 1032 1040 while (right > left && isTrimWhitespace(str[right - 1])) -
trunk/JavaScriptCore/runtime/UString.cpp
r54545 r54789 168 168 } 169 169 170 UString::UString(const char* c, intlength)170 UString::UString(const char* c, unsigned length) 171 171 : m_rep(Rep::create(c, length)) 172 172 { 173 173 } 174 174 175 UString::UString(const UChar* c, intlength)175 UString::UString(const UChar* c, unsigned length) 176 176 { 177 177 if (length == 0) … … 207 207 } 208 208 209 return UString(p, static_cast< int>(end - p));209 return UString(p, static_cast<unsigned>(end - p)); 210 210 } 211 211 … … 240 240 } 241 241 242 return UString(p, static_cast< int>(end - p));242 return UString(p, static_cast<unsigned>(end - p)); 243 243 } 244 244 … … 258 258 } 259 259 260 return UString(p, static_cast< int>(end - p));260 return UString(p, static_cast<unsigned>(end - p)); 261 261 } 262 262 … … 287 287 } 288 288 289 return UString(p, static_cast<int>(end - p));289 return UString(p, end - p); 290 290 } 291 291 … … 300 300 bool UString::getCString(CStringBuffer& buffer) const 301 301 { 302 intlength = size();303 intneededSize = length + 1;302 unsigned length = size(); 303 unsigned neededSize = length + 1; 304 304 buffer.resize(neededSize); 305 305 char* buf = buffer.data(); … … 325 325 static char* asciiBuffer = 0; 326 326 327 intlength = size();328 intneededSize = length + 1;327 unsigned length = size(); 328 unsigned neededSize = length + 1; 329 329 delete[] asciiBuffer; 330 330 asciiBuffer = new char[neededSize]; … … 356 356 } 357 357 358 UChar UString::operator[]( intpos) const358 UChar UString::operator[](unsigned pos) const 359 359 { 360 360 if (pos >= size()) … … 496 496 497 497 // Empty string is not OK. 498 intlen = m_rep->size();498 unsigned len = m_rep->size(); 499 499 if (len == 0) 500 500 return 0; … … 540 540 } 541 541 542 int UString::find(const UString& f, int pos) const 543 { 544 int fsz = f.size(); 545 546 if (pos < 0) 547 pos = 0; 542 unsigned UString::find(const UString& f, unsigned pos) const 543 { 544 unsigned fsz = f.size(); 548 545 549 546 if (fsz == 1) { … … 554 551 return static_cast<int>(c - data()); 555 552 } 556 return -1;557 } 558 559 intsz = size();553 return NotFound; 554 } 555 556 unsigned sz = size(); 560 557 if (sz < fsz) 561 return -1;558 return NotFound; 562 559 if (fsz == 0) 563 560 return pos; 564 561 const UChar* end = data() + sz - fsz; 565 intfsizeminusone = (fsz - 1) * sizeof(UChar);562 unsigned fsizeminusone = (fsz - 1) * sizeof(UChar); 566 563 const UChar* fdata = f.data(); 567 564 unsigned short fchar = fdata[0]; … … 572 569 } 573 570 574 return -1; 575 } 576 577 int UString::find(UChar ch, int pos) const 578 { 579 if (pos < 0) 580 pos = 0; 571 return NotFound; 572 } 573 574 unsigned UString::find(UChar ch, unsigned pos) const 575 { 581 576 const UChar* end = data() + size(); 582 577 for (const UChar* c = data() + pos; c < end; c++) { … … 585 580 } 586 581 587 return -1;588 } 589 590 int UString::rfind(const UString& f, intpos) const591 { 592 intsz = size();593 intfsz = f.size();582 return NotFound; 583 } 584 585 unsigned UString::rfind(const UString& f, unsigned pos) const 586 { 587 unsigned sz = size(); 588 unsigned fsz = f.size(); 594 589 if (sz < fsz) 595 return -1; 596 if (pos < 0) 597 pos = 0; 590 return NotFound; 598 591 if (pos > sz - fsz) 599 592 pos = sz - fsz; 600 593 if (fsz == 0) 601 594 return pos; 602 intfsizeminusone = (fsz - 1) * sizeof(UChar);595 unsigned fsizeminusone = (fsz - 1) * sizeof(UChar); 603 596 const UChar* fdata = f.data(); 604 597 for (const UChar* c = data() + pos; c >= data(); c--) { … … 607 600 } 608 601 609 return -1;610 } 611 612 int UString::rfind(UChar ch, intpos) const602 return NotFound; 603 } 604 605 unsigned UString::rfind(UChar ch, unsigned pos) const 613 606 { 614 607 if (isEmpty()) 615 return -1;608 return NotFound; 616 609 if (pos + 1 >= size()) 617 610 pos = size() - 1; … … 621 614 } 622 615 623 return -1; 624 } 625 626 UString UString::substr(int pos, int len) const 627 { 628 int s = size(); 629 630 if (pos < 0) 631 pos = 0; 632 else if (pos >= s) 616 return NotFound; 617 } 618 619 UString UString::substr(unsigned pos, unsigned len) const 620 { 621 unsigned s = size(); 622 623 if (pos >= s) 633 624 pos = s; 634 if (len < 0) 635 len = s; 636 if (pos + len >= s) 637 len = s - pos; 625 unsigned limit = s - pos; 626 if (len > limit) 627 len = limit; 638 628 639 629 if (pos == 0 && len == s) … … 662 652 bool operator<(const UString& s1, const UString& s2) 663 653 { 664 const intl1 = s1.size();665 const intl2 = s2.size();666 const intlmin = l1 < l2 ? l1 : l2;654 const unsigned l1 = s1.size(); 655 const unsigned l2 = s2.size(); 656 const unsigned lmin = l1 < l2 ? l1 : l2; 667 657 const UChar* c1 = s1.data(); 668 658 const UChar* c2 = s2.data(); 669 intl = 0;659 unsigned l = 0; 670 660 while (l < lmin && *c1 == *c2) { 671 661 c1++; … … 681 671 bool operator>(const UString& s1, const UString& s2) 682 672 { 683 const intl1 = s1.size();684 const intl2 = s2.size();685 const intlmin = l1 < l2 ? l1 : l2;673 const unsigned l1 = s1.size(); 674 const unsigned l2 = s2.size(); 675 const unsigned lmin = l1 < l2 ? l1 : l2; 686 676 const UChar* c1 = s1.data(); 687 677 const UChar* c2 = s2.data(); 688 intl = 0;678 unsigned l = 0; 689 679 while (l < lmin && *c1 == *c2) { 690 680 c1++; … … 700 690 int compare(const UString& s1, const UString& s2) 701 691 { 702 const intl1 = s1.size();703 const intl2 = s2.size();704 const intlmin = l1 < l2 ? l1 : l2;692 const unsigned l1 = s1.size(); 693 const unsigned l2 = s2.size(); 694 const unsigned lmin = l1 < l2 ? l1 : l2; 705 695 const UChar* c1 = s1.data(); 706 696 const UChar* c2 = s2.data(); 707 intl = 0;697 unsigned l = 0; 708 698 while (l < lmin && *c1 == *c2) { 709 699 c1++; … … 723 713 bool equal(const UString::Rep* r, const UString::Rep* b) 724 714 { 725 intlength = r->size();715 unsigned length = r->size(); 726 716 if (length != b->size()) 727 717 return false; 728 718 const UChar* d = r->data(); 729 719 const UChar* s = b->data(); 730 for ( inti = 0; i != length; ++i) {720 for (unsigned i = 0; i != length; ++i) { 731 721 if (d[i] != s[i]) 732 722 return false; … … 738 728 { 739 729 // Allocate a buffer big enough to hold all the characters. 740 const intlength = size();730 const unsigned length = size(); 741 731 Vector<char, 1024> buffer(length * 3); 742 732 -
trunk/JavaScriptCore/runtime/UString.h
r54788 r54789 83 83 UString(); 84 84 UString(const char*); // Constructor for null-terminated string. 85 UString(const char*, intlength);86 UString(const UChar*, intlength);85 UString(const char*, unsigned length); 86 UString(const UChar*, unsigned length); 87 87 UString(const Vector<UChar>& buffer); 88 88 … … 137 137 bool is8Bit() const; 138 138 139 intsize() const { return m_rep->size(); }140 141 UChar operator[]( intpos) const;139 unsigned size() const { return m_rep->size(); } 140 141 UChar operator[](unsigned pos) const; 142 142 143 143 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; … … 151 151 unsigned toArrayIndex(bool* ok = 0) const; 152 152 153 int find(const UString& f, int pos = 0) const; 154 int find(UChar, int pos = 0) const; 155 int rfind(const UString& f, int pos) const; 156 int rfind(UChar, int pos) const; 157 158 UString substr(int pos = 0, int len = -1) const; 153 static const unsigned NotFound = 0xFFFFFFFFu; 154 unsigned find(const UString& f, unsigned pos = 0) const; 155 unsigned find(UChar, unsigned pos = 0) const; 156 unsigned rfind(const UString& f, unsigned pos) const; 157 unsigned rfind(UChar, unsigned pos) const; 158 159 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 159 160 160 161 static const UString& null() { return *s_nullUString; } … … 182 183 ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2) 183 184 { 184 intsize = s1.size();185 unsigned size = s1.size(); 185 186 switch (size) { 186 187 case 0: … … 246 247 // this runs too much risk of a tiny initial string holding down a 247 248 // huge buffer. 248 // FIXME: this should be size_t but that would cause warnings until we 249 // fix UString sizes to be size_t instead of int 250 static const int minShareSize = Heap::minExtraCost / sizeof(UChar); 249 static const unsigned minShareSize = Heap::minExtraCost / sizeof(UChar); 251 250 252 251 struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > { -
trunk/JavaScriptCore/runtime/UStringImpl.cpp
r54743 r54789 51 51 } 52 52 53 PassRefPtr<UStringImpl> UStringImpl::create(const char* c, intlength)53 PassRefPtr<UStringImpl> UStringImpl::create(const char* c, unsigned length) 54 54 { 55 55 ASSERT(c); … … 60 60 UChar* d; 61 61 PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d); 62 for ( inti = 0; i < length; i++)62 for (unsigned i = 0; i < length; i++) 63 63 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend 64 64 return result; 65 65 } 66 66 67 PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, intlength)67 PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, unsigned length) 68 68 { 69 69 UChar* newBuffer; -
trunk/JavaScriptCore/runtime/UStringImpl.h
r54743 r54789 54 54 55 55 static PassRefPtr<UStringImpl> create(const char* c); 56 static PassRefPtr<UStringImpl> create(const char* c, intlength);57 static PassRefPtr<UStringImpl> create(const UChar* buffer, intlength);58 59 static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, int offset, intlength)56 static PassRefPtr<UStringImpl> create(const char* c, unsigned length); 57 static PassRefPtr<UStringImpl> create(const UChar* buffer, unsigned length); 58 59 static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, unsigned offset, unsigned length) 60 60 { 61 61 ASSERT(rep); … … 64 64 } 65 65 66 static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, intlength)66 static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, unsigned length) 67 67 { 68 68 return adoptRef(new UStringImpl(buffer, length, sharedBuffer)); … … 101 101 SharedUChar* sharedBuffer(); 102 102 UChar* data() const { return m_data; } 103 intsize() const { return m_length; }103 unsigned size() const { return m_length; } 104 104 size_t cost() 105 105 { … … 137 137 } 138 138 139 static unsigned computeHash(const UChar* s, int length) { ASSERT(length >= 0);return WTF::stringHash(s, length); }140 static unsigned computeHash(const char* s, int length) { ASSERT(length >= 0);return WTF::stringHash(s, length); }139 static unsigned computeHash(const UChar* s, unsigned length) { return WTF::stringHash(s, length); } 140 static unsigned computeHash(const char* s, unsigned length) { return WTF::stringHash(s, length); } 141 141 static unsigned computeHash(const char* s) { return WTF::stringHash(s); } 142 142 … … 163 163 164 164 // Used to construct normal strings with an internal or external buffer. 165 UStringImpl(UChar* data, intlength, BufferOwnership ownership)165 UStringImpl(UChar* data, unsigned length, BufferOwnership ownership) 166 166 : m_data(data) 167 167 , m_buffer(0) … … 178 178 // static strings will be shared across threads & ref-counted in a non-threadsafe manner. 179 179 enum StaticStringConstructType { ConstructStaticString }; 180 UStringImpl(UChar* data, intlength, StaticStringConstructType)180 UStringImpl(UChar* data, unsigned length, StaticStringConstructType) 181 181 : m_data(data) 182 182 , m_buffer(0) … … 189 189 190 190 // Used to create new strings that are a substring of an existing string. 191 UStringImpl(UChar* data, intlength, PassRefPtr<UStringImpl> base)191 UStringImpl(UChar* data, unsigned length, PassRefPtr<UStringImpl> base) 192 192 : m_data(data) 193 193 , m_bufferSubstring(base.releaseRef()) … … 205 205 206 206 // Used to construct new strings sharing an existing shared buffer. 207 UStringImpl(UChar* data, intlength, PassRefPtr<SharedUChar> sharedBuffer)207 UStringImpl(UChar* data, unsigned length, PassRefPtr<SharedUChar> sharedBuffer) 208 208 : m_data(data) 209 209 , m_bufferShared(sharedBuffer.releaseRef()) … … 221 221 222 222 // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings. 223 static const ints_minLengthToShare = 10;223 static const unsigned s_minLengthToShare = 10; 224 224 static const unsigned s_copyCharsInlineCutOff = 20; 225 225 // We initialize and increment/decrement the refCount for all normal (non-static) strings by the value 2. 226 226 // We initialize static strings with an odd number (specifically, 1), such that the refCount cannot reach zero. 227 227 static const unsigned s_refCountMask = 0xFFFFFFF0; 228 static const ints_refCountIncrement = 0x20;229 static const ints_refCountFlagStatic = 0x10;228 static const unsigned s_refCountIncrement = 0x20; 229 static const unsigned s_refCountFlagStatic = 0x10; 230 230 static const unsigned s_refCountFlagHasReportedCost = 0x8; 231 231 static const unsigned s_refCountFlagIsIdentifier = 0x4; … … 245 245 SharedUChar* m_bufferShared; 246 246 }; 247 intm_length;247 unsigned m_length; 248 248 unsigned m_refCountAndFlags; 249 249 mutable unsigned m_hash; -
trunk/WebCore/ChangeLog
r54786 r54789 1 2010-02-15 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Geoff Garen. 4 5 Bug 34952 - String lengths in UString should be unsigned. 6 This matches WebCore::StringImpl, and better unifies behaviour throughout JSC. 7 8 * bindings/js/JSDOMWindowCustom.cpp: 9 (WebCore::JSDOMWindow::atob): 10 (WebCore::JSDOMWindow::btoa): 11 1 12 2010-02-15 Gustavo Noronha Silva <gustavo.noronha@collabora.co.uk> 2 13 -
trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp
r54681 r54789 955 955 956 956 Vector<char> in(s.size()); 957 for ( inti = 0; i < s.size(); ++i)957 for (unsigned i = 0; i < s.size(); ++i) 958 958 in[i] = static_cast<char>(s.data()[i]); 959 959 Vector<char> out; … … 981 981 982 982 Vector<char> in(s.size()); 983 for ( inti = 0; i < s.size(); ++i)983 for (unsigned i = 0; i < s.size(); ++i) 984 984 in[i] = static_cast<char>(s.data()[i]); 985 985 Vector<char> out;
Note: See TracChangeset
for help on using the changeset viewer.