Changeset 102146 in webkit
- Timestamp:
- Dec 6, 2011, 9:21:11 AM (15 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
runtime/JSGlobalObjectFunctions.cpp (modified) (9 diffs)
-
runtime/JSStringBuilder.h (modified) (1 diff)
-
wtf/text/StringBuilder.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r102132 r102146 1 2011-12-06 Michael Saboff <msaboff@apple.com> 2 3 Add 8 bit paths to global object functions 4 https://bugs.webkit.org/show_bug.cgi?id=73875 5 6 Added 8 bit paths for converions methods. 7 8 This is worth 1.5% on kraken audio-oscillator, 9 1.6% on stanford-crypto-ccm and 2.5% on 10 stanford-crypto-sha256-iterative. See bug for 11 a full report. 12 13 Reviewed by Oliver Hunt. 14 15 * runtime/JSGlobalObjectFunctions.cpp: 16 (JSC::decode): Split into a templated helper. 17 (JSC::parseInt): Split into a templated helper. 18 (JSC::parseFloat): Added an 8 bit path 19 (JSC::globalFuncEscape): Added 8 bit path 20 (JSC::globalFuncUnescape): Added 8 bit path 21 * runtime/JSStringBuilder.h: 22 (JSC::JSStringBuilder::append): New append for LChar 23 * wtf/text/StringBuilder.h: 24 (WTF::StringBuilder::append): New append for LChar 25 1 26 2011-11-21 Balazs Kelemen <kbalazs@webkit.org> 2 27 -
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r101151 r102146 72 72 } 73 73 74 static JSValue decode(ExecState* exec, const char* doNotUnescape, bool strict) 74 template <typename CharType> 75 ALWAYS_INLINE 76 static JSValue decode(ExecState* exec, const CharType* characters, int length, const char* doNotUnescape, bool strict) 75 77 { 76 78 JSStringBuilder builder; 77 UString str = exec->argument(0).toString(exec);78 79 int k = 0; 79 int len = str.length();80 const UChar* d = str.characters();81 80 UChar u = 0; 82 while (k < len ) {83 const UChar* p = d+ k;84 UCharc = *p;81 while (k < length) { 82 const CharType* p = characters + k; 83 CharType c = *p; 85 84 if (c == '%') { 86 85 int charLen = 0; 87 if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {88 const char b0 = Lexer< UChar>::convertHex(p[1], p[2]);86 if (k <= length - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) { 87 const char b0 = Lexer<CharType>::convertHex(p[1], p[2]); 89 88 const int sequenceLen = UTF8SequenceLength(b0); 90 if (sequenceLen != 0 && k <= len- sequenceLen * 3) {89 if (sequenceLen && k <= length - sequenceLen * 3) { 91 90 charLen = sequenceLen * 3; 92 91 char sequence[5]; 93 92 sequence[0] = b0; 94 93 for (int i = 1; i < sequenceLen; ++i) { 95 const UChar* q = p + i * 3;94 const CharType* q = p + i * 3; 96 95 if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2])) 97 sequence[i] = Lexer< UChar>::convertHex(q[1], q[2]);96 sequence[i] = Lexer<CharType>::convertHex(q[1], q[2]); 98 97 else { 99 98 charLen = 0; … … 120 119 // The only case where we don't use "strict" mode is the "unescape" function. 121 120 // For that, it's good to support the wonky "%u" syntax for compatibility with WinIE. 122 if (k <= len - 6 && p[1] == 'u'121 if (k <= length - 6 && p[1] == 'u' 123 122 && isASCIIHexDigit(p[2]) && isASCIIHexDigit(p[3]) 124 123 && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) { … … 128 127 } 129 128 if (charLen && (u == 0 || u >= 128 || !strchr(doNotUnescape, u))) { 130 c = u; 131 k += charLen - 1; 129 if (u < 256) 130 builder.append(static_cast<LChar>(u)); 131 else 132 builder.append(u); 133 k += charLen; 134 continue; 132 135 } 133 136 } … … 136 139 } 137 140 return builder.build(exec); 141 } 142 143 static JSValue decode(ExecState* exec, const char* doNotUnescape, bool strict) 144 { 145 JSStringBuilder builder; 146 UString str = exec->argument(0).toString(exec); 147 148 if (str.is8Bit()) 149 return decode(exec, str.characters8(), str.length(), doNotUnescape, strict); 150 return decode(exec, str.characters16(), str.length(), doNotUnescape, strict); 138 151 } 139 152 … … 218 231 } 219 232 220 static double parseInt(const UString& s, int radix) 233 template <typename CharType> 234 ALWAYS_INLINE 235 static double parseInt(const UString& s, const CharType* data, int radix) 221 236 { 222 237 int length = s.length(); 223 const UChar* data = s.characters();224 238 int p = 0; 225 239 … … 274 288 275 289 return sign * number; 290 } 291 292 static double parseInt(const UString& s, int radix) 293 { 294 if (s.is8Bit()) 295 return parseInt(s, s.characters8(), radix); 296 return parseInt(s, s.characters16(), radix); 276 297 } 277 298 … … 427 448 } 428 449 429 const UChar* data = s.characters(); 450 if (s.is8Bit()) { 451 const LChar* data = s.characters8(); 452 const LChar* end = data + size; 453 454 // Skip leading white space. 455 for (; data < end; ++data) { 456 if (!isStrWhiteSpace(*data)) 457 break; 458 } 459 460 // Empty string. 461 if (data == end) 462 return std::numeric_limits<double>::quiet_NaN(); 463 464 return jsStrDecimalLiteral(data, end); 465 } 466 467 const UChar* data = s.characters16(); 430 468 const UChar* end = data + size; 431 469 … … 565 603 JSStringBuilder builder; 566 604 UString str = exec->argument(0).toString(exec); 567 const UChar* c = str.characters(); 605 if (str.is8Bit()) { 606 const LChar* c = str.characters8(); 607 for (unsigned k = 0; k < str.length(); k++, c++) { 608 int u = c[0]; 609 if (u && strchr(do_not_escape, static_cast<char>(u))) 610 builder.append(c, 1); 611 else { 612 char tmp[4]; 613 snprintf(tmp, sizeof(tmp), "%%%02X", u); 614 builder.append(tmp); 615 } 616 } 617 618 return JSValue::encode(builder.build(exec)); 619 } 620 621 const UChar* c = str.characters16(); 568 622 for (unsigned k = 0; k < str.length(); k++, c++) { 569 623 int u = c[0]; … … 590 644 int k = 0; 591 645 int len = str.length(); 592 while (k < len) { 593 const UChar* c = str.characters() + k; 594 UChar u; 595 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') { 596 if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) { 597 u = Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5]); 646 647 if (str.is8Bit()) { 648 const LChar* characters = str.characters8(); 649 650 while (k < len) { 651 const LChar* c = characters + k; 652 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') { 653 if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) { 654 builder.append(Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5])); 655 k += 5; 656 } 657 } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) { 658 builder.append(Lexer<LChar>::convertHex(c[1], c[2])); 659 k += 2; 660 } else 661 builder.append(*c); 662 k++; 663 } 664 } else { 665 const UChar* characters = str.characters16(); 666 667 while (k < len) { 668 const UChar* c = characters + k; 669 UChar u; 670 if (c[0] == '%' && k <= len - 6 && c[1] == 'u') { 671 if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) { 672 u = Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5]); 673 c = &u; 674 k += 5; 675 } 676 } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) { 677 u = UChar(Lexer<UChar>::convertHex(c[1], c[2])); 598 678 c = &u; 599 k += 5;679 k += 2; 600 680 } 601 } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) { 602 u = UChar(Lexer<UChar>::convertHex(c[1], c[2])); 603 c = &u; 604 k += 2; 605 } 606 k++; 607 builder.append(*c); 681 k++; 682 builder.append(*c); 683 } 608 684 } 609 685 -
trunk/Source/JavaScriptCore/runtime/JSStringBuilder.h
r101147 r102146 73 73 } 74 74 75 void append(const LChar* str, size_t len) 76 { 77 if (m_is8Bit) { 78 m_okay &= buffer8.tryAppend(str, len); 79 return; 80 } 81 m_okay &= buffer8.tryReserveCapacity(buffer16.size() + len); 82 for (size_t i = 0; i < len; i++) { 83 UChar u = str[i]; 84 m_okay &= buffer16.tryAppend(&u, 1); 85 } 86 } 87 75 88 void append(const UChar* str, size_t len) 76 89 { -
trunk/Source/JavaScriptCore/wtf/text/StringBuilder.h
r102017 r102146 81 81 } 82 82 83 void append(LChar c) 84 { 85 if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) { 86 if (m_is8Bit) 87 m_bufferCharacters8[m_length++] = c; 88 else 89 m_bufferCharacters16[m_length++] = c; 90 } else 91 append(&c, 1); 92 } 93 83 94 void append(char c) 84 95 {
Note:
See TracChangeset
for help on using the changeset viewer.