Changeset 264293 in webkit
- Timestamp:
- Jul 12, 2020, 11:27:19 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
-
JavaScriptCore/ChangeLog (modified) (1 diff)
-
JavaScriptCore/runtime/IntlObject.cpp (modified) (1 diff)
-
JavaScriptCore/runtime/IntlObject.h (modified) (1 diff)
-
JavaScriptCore/runtime/IntlObjectInlines.h (modified) (1 diff)
-
JavaScriptCore/runtime/StringPrototype.cpp (modified) (3 diffs)
-
WTF/ChangeLog (modified) (1 diff)
-
WTF/wtf/text/ASCIILiteral.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r264287 r264293 1 2020-07-12 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] String.protoytpe.toLocaleLowerCase's availableLocales HashSet is inefficient 4 https://bugs.webkit.org/show_bug.cgi?id=213158 5 6 Reviewed by Darin Adler. 7 8 Currently, we are always creating the same HashSet every time String.protoytpe.toLocaleLowerCase is called. 9 We changed bestAvailableLocale to take predicate function. And we pass a predicate which returns true for 10 case-sensitive locales. 11 12 * runtime/IntlObject.cpp: 13 (JSC::bestAvailableLocale): 14 * runtime/IntlObject.h: 15 * runtime/IntlObjectInlines.h: 16 (JSC::bestAvailableLocale): 17 * runtime/StringPrototype.cpp: 18 (JSC::computeTwoCharacters16Code): 19 (JSC::toLocaleCase): 20 1 21 2020-07-12 Yusuke Suzuki <ysuzuki@apple.com> 2 22 -
trunk/Source/JavaScriptCore/runtime/IntlObject.cpp
r263227 r264293 477 477 String bestAvailableLocale(const HashSet<String>& availableLocales, const String& locale) 478 478 { 479 // BestAvailableLocale (availableLocales, locale) 480 // https://tc39.github.io/ecma402/#sec-bestavailablelocale 481 482 String candidate = locale; 483 while (!candidate.isEmpty()) { 484 if (availableLocales.contains(candidate)) 485 return candidate; 486 487 size_t pos = candidate.reverseFind('-'); 488 if (pos == notFound) 489 return String(); 490 491 if (pos >= 2 && candidate[pos - 2] == '-') 492 pos -= 2; 493 494 candidate = candidate.substring(0, pos); 495 } 496 497 return String(); 479 return bestAvailableLocale(locale, [&](const String& candidate) { 480 return availableLocales.contains(candidate); 481 }); 498 482 } 499 483 -
trunk/Source/JavaScriptCore/runtime/IntlObject.h
r261215 r264293 76 76 String removeUnicodeLocaleExtension(const String& locale); 77 77 String bestAvailableLocale(const HashSet<String>& availableLocales, const String& requestedLocale); 78 template<typename Predicate> String bestAvailableLocale(const String& requestedLocale, Predicate); 78 79 Vector<String> numberingSystemsForLocale(const String& locale); 79 80 -
trunk/Source/JavaScriptCore/runtime/IntlObjectInlines.h
r259767 r264293 33 33 namespace JSC { 34 34 35 template<typename Predicate> String bestAvailableLocale(const String& locale, Predicate predicate) 36 { 37 // BestAvailableLocale (availableLocales, locale) 38 // https://tc39.github.io/ecma402/#sec-bestavailablelocale 39 40 String candidate = locale; 41 while (!candidate.isEmpty()) { 42 if (predicate(candidate)) 43 return candidate; 44 45 size_t pos = candidate.reverseFind('-'); 46 if (pos == notFound) 47 return String(); 48 49 if (pos >= 2 && candidate[pos - 2] == '-') 50 pos -= 2; 51 52 candidate = candidate.substring(0, pos); 53 } 54 55 return String(); 56 } 57 35 58 template<typename IntlInstance, typename Constructor, typename Factory> 36 59 JSValue constructIntlInstanceWithWorkaroundForLegacyIntlConstructor(JSGlobalObject* globalObject, JSValue thisValue, Constructor* callee, Factory factory) -
trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp
r263905 r264293 31 31 #include "InterpreterInlines.h" 32 32 #include "IntlCollator.h" 33 #include "IntlObject .h"33 #include "IntlObjectInlines.h" 34 34 #include "JITCodeInlines.h" 35 35 #include "JSArray.h" … … 1542 1542 } 1543 1543 1544 template<typename StringType> 1545 static constexpr uint32_t computeTwoCharacters16Code(const StringType& string) 1546 { 1547 return static_cast<uint16_t>(string.characterAt(0)) | (static_cast<uint32_t>(static_cast<uint16_t>(string.characterAt(1))) << 16); 1548 } 1549 1544 1550 enum class CaseConversionMode { 1545 1551 Upper, … … 1589 1595 // 10. Let availableLocales be a List with the language tags of the languages for which the Unicode character database contains language sensitive case mappings. 1590 1596 // Note 1: As of Unicode 5.1, the availableLocales list contains the elements "az", "el", "lt", and "tr". 1591 // FIXME: Creating HashSet for these 4 locales every time is inefficient.1592 // https://bugs.webkit.org/show_bug.cgi?id=2131581593 const HashSet<String> availableLocales({ "az"_s, "el"_s, "lt"_s, "tr"_s });1594 1595 1597 // 11. Let locale be BestAvailableLocale(availableLocales, noExtensionsLocale). 1596 String locale = bestAvailableLocale(availableLocales, noExtensionsLocale); 1598 String locale = bestAvailableLocale(noExtensionsLocale, [](const String& candidate) { 1599 if (candidate.length() != 2) 1600 return false; 1601 switch (computeTwoCharacters16Code(candidate)) { 1602 case computeTwoCharacters16Code("az"_s): 1603 case computeTwoCharacters16Code("el"_s): 1604 case computeTwoCharacters16Code("lt"_s): 1605 case computeTwoCharacters16Code("tr"_s): 1606 return true; 1607 default: 1608 return false; 1609 } 1610 }); 1597 1611 1598 1612 // 12. If locale is undefined, let locale be "und". -
trunk/Source/WTF/ChangeLog
r264290 r264293 1 2020-07-12 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [JSC] String.protoytpe.toLocaleLowerCase's availableLocales HashSet is inefficient 4 https://bugs.webkit.org/show_bug.cgi?id=213158 5 6 Reviewed by Darin Adler. 7 8 Add characterAt method to ASCIILiteral. 9 10 * wtf/text/ASCIILiteral.h: 11 1 12 2020-07-12 Darin Adler <darin@apple.com> 2 13 -
trunk/Source/WTF/wtf/text/ASCIILiteral.h
r263665 r264293 53 53 size_t length() const { return strlen(m_characters); } 54 54 55 constexpr char characterAt(unsigned index) const { return m_characters[index]; } 56 55 57 private: 56 58 constexpr explicit ASCIILiteral(const char* characters) : m_characters(characters) { }
Note:
See TracChangeset
for help on using the changeset viewer.