Title: [266432] branches/safari-610-branch
Revision
266432
Author
[email protected]
Date
2020-09-01 18:19:17 -0700 (Tue, 01 Sep 2020)

Log Message

Cherry-pick r266178. rdar://problem/68164567

    [JSC] Add ASCII comparison fast path for IntlCollator
    https://bugs.webkit.org/show_bug.cgi?id=215798

    Reviewed by Darin Adler, Ross Kirsling, and Saam Barati.

    JSTests:

    * stress/string-locale-compare-uca-ducet.js: Added.
    (shouldBe):
    * stress/string-localeCompare.js:
    (data.sort):

    Source/_javascript_Core:

    The idea behind this change is the following: ICU Collator's comparison is too slow. We should have fast path for ASCII strings when we know this equals to ICU Collator's result.
    The problem is that even for ASCII strings, collation is super complicated!

        1. Unicode defines Unicode Collation Algorithm (UCA). To perform collation, it uses collation element tables which defines weights on various levels per code point. UCA also offers
           the Default Unicode Collation Element Table (DUCET). This UCA with DUCET is used when using ICU Root Collator.
        2. UCA collation consists of rules, which defines how collation works. And ICU locales define customized collations by adding special rules to that.
        3. UCA behaves differently by using different options.

    Based on that, our observation is that some of major locales are not defining additional rules in (2). This means that they behaves the same to UCA with DUCET.
    This patch implements a simplified version of comparison which generates the same results for ASCII strings (excluding control characters) to UCA with DUCET. This fast path can be usable only when the following conditions are met.

        1. The collator does not have additional rules to ICU Root Colator.
        2. The collator is using default options.

    These checks are very important since there are a lot of edge-case locales. For example,

        1. th (Thai language) ignores punctuations (even including ASCII punctuations) by default. This is defined as ignore-punctuations option is enabled by default, so without (2)'s check, th comparison becomes wrong.
        2. There are contraction concept (multiple letters behave as a single letter). "ch" letters are ordered interestingly in Czech language. So even in ASCII, Czech shows very interesting collation behavior.

    So we cannot safely take this fast path without carefully querying the information to ICU.

    This shows 37% improvement in JetStream2/cdjs in en-US environment.

    * runtime/IntlCollator.cpp:
    (JSC::IntlCollator::initializeCollator):
    (JSC::IntlCollator::compareStrings const):
    (JSC::canDoASCIIUCADUCETComparisonWithUCollator):
    (JSC::IntlCollator::updateCanDoASCIIUCADUCETComparison const):
    (JSC::IntlCollator::checkICULocaleInvariants):
    * runtime/IntlCollator.h:
    * runtime/IntlObject.cpp:
    (JSC::intlCollatorAvailableLocales):
    * runtime/IntlObject.h:
    * runtime/IntlObjectInlines.h:
    (JSC::canUseASCIIUCADUCETComparison):
    (JSC::compareASCIIWithUCADUCET):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266178 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-610-branch/JSTests/ChangeLog (266431 => 266432)


--- branches/safari-610-branch/JSTests/ChangeLog	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/JSTests/ChangeLog	2020-09-02 01:19:17 UTC (rev 266432)
@@ -1,3 +1,72 @@
+2020-09-01  Alan Coon  <[email protected]>
+
+        Cherry-pick r266178. rdar://problem/68164567
+
+    [JSC] Add ASCII comparison fast path for IntlCollator
+    https://bugs.webkit.org/show_bug.cgi?id=215798
+    
+    Reviewed by Darin Adler, Ross Kirsling, and Saam Barati.
+    
+    JSTests:
+    
+    * stress/string-locale-compare-uca-ducet.js: Added.
+    (shouldBe):
+    * stress/string-localeCompare.js:
+    (data.sort):
+    
+    Source/_javascript_Core:
+    
+    The idea behind this change is the following: ICU Collator's comparison is too slow. We should have fast path for ASCII strings when we know this equals to ICU Collator's result.
+    The problem is that even for ASCII strings, collation is super complicated!
+    
+        1. Unicode defines Unicode Collation Algorithm (UCA). To perform collation, it uses collation element tables which defines weights on various levels per code point. UCA also offers
+           the Default Unicode Collation Element Table (DUCET). This UCA with DUCET is used when using ICU Root Collator.
+        2. UCA collation consists of rules, which defines how collation works. And ICU locales define customized collations by adding special rules to that.
+        3. UCA behaves differently by using different options.
+    
+    Based on that, our observation is that some of major locales are not defining additional rules in (2). This means that they behaves the same to UCA with DUCET.
+    This patch implements a simplified version of comparison which generates the same results for ASCII strings (excluding control characters) to UCA with DUCET. This fast path can be usable only when the following conditions are met.
+    
+        1. The collator does not have additional rules to ICU Root Colator.
+        2. The collator is using default options.
+    
+    These checks are very important since there are a lot of edge-case locales. For example,
+    
+        1. th (Thai language) ignores punctuations (even including ASCII punctuations) by default. This is defined as ignore-punctuations option is enabled by default, so without (2)'s check, th comparison becomes wrong.
+        2. There are contraction concept (multiple letters behave as a single letter). "ch" letters are ordered interestingly in Czech language. So even in ASCII, Czech shows very interesting collation behavior.
+    
+    So we cannot safely take this fast path without carefully querying the information to ICU.
+    
+    This shows 37% improvement in JetStream2/cdjs in en-US environment.
+    
+    * runtime/IntlCollator.cpp:
+    (JSC::IntlCollator::initializeCollator):
+    (JSC::IntlCollator::compareStrings const):
+    (JSC::canDoASCIIUCADUCETComparisonWithUCollator):
+    (JSC::IntlCollator::updateCanDoASCIIUCADUCETComparison const):
+    (JSC::IntlCollator::checkICULocaleInvariants):
+    * runtime/IntlCollator.h:
+    * runtime/IntlObject.cpp:
+    (JSC::intlCollatorAvailableLocales):
+    * runtime/IntlObject.h:
+    * runtime/IntlObjectInlines.h:
+    (JSC::canUseASCIIUCADUCETComparison):
+    (JSC::compareASCIIWithUCADUCET):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-26  Yusuke Suzuki  <[email protected]>
+
+            [JSC] Add ASCII comparison fast path for IntlCollator
+            https://bugs.webkit.org/show_bug.cgi?id=215798
+
+            Reviewed by Darin Adler, Ross Kirsling, and Saam Barati.
+
+            * stress/string-locale-compare-uca-ducet.js: Added.
+            (shouldBe):
+            * stress/string-localeCompare.js:
+            (data.sort):
+
 2020-08-28  Alan Coon  <[email protected]>
 
         Cherry-pick r266254. rdar://problem/67949890

Added: branches/safari-610-branch/JSTests/stress/string-locale-compare-uca-ducet.js (0 => 266432)


--- branches/safari-610-branch/JSTests/stress/string-locale-compare-uca-ducet.js	                        (rev 0)
+++ branches/safari-610-branch/JSTests/stress/string-locale-compare-uca-ducet.js	2020-09-02 01:19:17 UTC (rev 266432)
@@ -0,0 +1,142 @@
+// Generated by using ICU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-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,-1,0,-1,1,
+1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,0,1,
+0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,
+];
+
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+var index = 0;
+for (var i = 0; i < 0x80; ++i) {
+    for (var j = 0; j < 0x80; ++j)
+        shouldBe(String.fromCharCode(i).localeCompare(String.fromCharCode(j), "en-US"), results[index++]);
+}

Modified: branches/safari-610-branch/JSTests/stress/string-localeCompare.js (266431 => 266432)


--- branches/safari-610-branch/JSTests/stress/string-localeCompare.js	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/JSTests/stress/string-localeCompare.js	2020-09-02 01:19:17 UTC (rev 266432)
@@ -92,3 +92,114 @@
 shouldBe('๒'.localeCompare('๑๐', 'en', { numeric: true }), -1);
 shouldBe('๐๑'.localeCompare('๑', 'en', { numeric: true }), 0);
 
+// th ignores punctuation by default.
+shouldBe('AA'.localeCompare('A-A', 'th'), 0);
+shouldBe('\u0000'.localeCompare('@', 'th'), 0);
+shouldBe('AA'.localeCompare('A-A', 'en'), 1);
+shouldBe('\u0000'.localeCompare('@', 'en'), -1);
+
+shouldBe('i'.localeCompare('x', 'ee'), 1);
+shouldBe('I'.localeCompare('x', 'ee'), 1);
+shouldBe('I'.localeCompare('X', 'ee'), 1);
+shouldBe('I'.localeCompare('x', 'ee'), 1);
+shouldBe('i'.localeCompare('x', 'en'), -1);
+shouldBe('I'.localeCompare('x', 'en'), -1);
+shouldBe('I'.localeCompare('X', 'en'), -1);
+shouldBe('I'.localeCompare('x', 'en'), -1);
+
+shouldBe('B'.localeCompare('a', 'en'), 1);
+shouldBe('b'.localeCompare('a', 'en'), 1);
+shouldBe('b'.localeCompare('A', 'en'), 1);
+shouldBe('B'.localeCompare('A', 'en'), 1);
+
+shouldBe('B'.localeCompare('c', 'en'), -1);
+shouldBe('b'.localeCompare('c', 'en'), -1);
+shouldBe('b'.localeCompare('C', 'en'), -1);
+shouldBe('B'.localeCompare('C', 'en'), -1);
+
+shouldBe('\u0000'.localeCompare('\u007f', 'en'), 0);
+
+shouldBe('ch'.localeCompare('ca', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('ci', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('da', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('h', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('i', 'cs-CZ'), -1);
+shouldBe('cb'.localeCompare('ca', 'cs-CZ'), 1);
+shouldBe('cb'.localeCompare('ci', 'cs-CZ'), -1);
+shouldBe('cb'.localeCompare('da', 'cs-CZ'), -1);
+shouldBe('ch'.localeCompare('ca', 'en'), 1);
+shouldBe('ch'.localeCompare('ci', 'en'), -1);
+shouldBe('ch'.localeCompare('da', 'en'), -1);
+shouldBe('ch'.localeCompare('h', 'en'), -1);
+shouldBe('ch'.localeCompare('i', 'en'), -1);
+shouldBe('cb'.localeCompare('ca', 'en'), 1);
+shouldBe('cb'.localeCompare('ci', 'en'), -1);
+shouldBe('cb'.localeCompare('da', 'en'), -1);
+
+shouldBe('ch'.localeCompare('ca', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('ci', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('da', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('h', 'cs-CZ'), 1);
+shouldBe('ch'.localeCompare('i', 'cs-CZ'), -1);
+shouldBe('cb'.localeCompare('ca', 'cs-CZ'), 1);
+shouldBe('cb'.localeCompare('ci', 'cs-CZ'), -1);
+shouldBe('cb'.localeCompare('da', 'cs-CZ'), -1);
+shouldBe('ch'.localeCompare('ca', 'en'), 1);
+shouldBe('ch'.localeCompare('ci', 'en'), -1);
+shouldBe('ch'.localeCompare('da', 'en'), -1);
+shouldBe('ch'.localeCompare('h', 'en'), -1);
+shouldBe('ch'.localeCompare('i', 'en'), -1);
+shouldBe('cb'.localeCompare('ca', 'en'), 1);
+shouldBe('cb'.localeCompare('ci', 'en'), -1);
+shouldBe('cb'.localeCompare('da', 'en'), -1);
+
+shouldBe('i'.localeCompare('X', 'az'), 1);
+shouldBe('I'.localeCompare('i', 'az'), -1);
+shouldBe('l'.localeCompare('q', 'az'), 1);
+shouldBe('i'.localeCompare('X', 'en'), -1);
+shouldBe('I'.localeCompare('i', 'en'), 1);
+shouldBe('l'.localeCompare('q', 'en'), -1);
+
+shouldBe('B'.localeCompare('E', 'haw'), 1);
+shouldBe('B'.localeCompare('E', 'en'), -1);
+
+shouldBe('J'.localeCompare('Y', 'lt'), 1);
+shouldBe('J'.localeCompare('Y', 'en'), -1);
+
+shouldBe('I'.localeCompare('i', 'tr'), -1);
+shouldBe('I'.localeCompare('i', 'en'), 1);
+
+shouldBe('T'.localeCompare('Z', 'et'), 1);
+shouldBe('T'.localeCompare('Z', 'en'), -1);
+
+shouldBe('J'.localeCompare('Y', 'lv'), 1);
+shouldBe('J'.localeCompare('Y', 'en'), -1);
+
+shouldBe('aa'.localeCompare('a', 'en'), 1);
+shouldBe('aa'.localeCompare('a ', 'en'), 1);
+shouldBe('aa'.localeCompare('b', 'en'), -1);
+shouldBe('aba'.localeCompare('aa', 'en'), 1);
+shouldBe('aba'.localeCompare('aaa', 'en'), 1);
+shouldBe('aba'.localeCompare('aaaa', 'en'), 1);
+
+shouldBe("a\u0000b".localeCompare("ab\u0000", 'en'), 0);
+shouldBe("bb".localeCompare("bb\u0000a", 'en'), -1);
+shouldBe("bb".localeCompare("bb\u0000c", 'en'), -1);
+shouldBe("bb".localeCompare("bba", 'en'), -1);
+shouldBe("\u0000\u0000\u0000".localeCompare("\u0000", 'en'), 0);
+
+var data = [
+    "de luge",
+    "de Luge",
+    "de\u002Dluge",
+    "de\u002DLuge",
+    "de\u2010luge",
+    "de\u2010Luge",
+    "death",
+    "deluge",
+    "deLuge",
+    "demark",
+];
+var result = JSON.stringify(data);
+data.sort(function (a, b) { return a.localeCompare(b, 'en'); });
+shouldBe(JSON.stringify(data), result);

Modified: branches/safari-610-branch/Source/_javascript_Core/ChangeLog (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/ChangeLog	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/ChangeLog	2020-09-02 01:19:17 UTC (rev 266432)
@@ -1,3 +1,104 @@
+2020-09-01  Alan Coon  <[email protected]>
+
+        Cherry-pick r266178. rdar://problem/68164567
+
+    [JSC] Add ASCII comparison fast path for IntlCollator
+    https://bugs.webkit.org/show_bug.cgi?id=215798
+    
+    Reviewed by Darin Adler, Ross Kirsling, and Saam Barati.
+    
+    JSTests:
+    
+    * stress/string-locale-compare-uca-ducet.js: Added.
+    (shouldBe):
+    * stress/string-localeCompare.js:
+    (data.sort):
+    
+    Source/_javascript_Core:
+    
+    The idea behind this change is the following: ICU Collator's comparison is too slow. We should have fast path for ASCII strings when we know this equals to ICU Collator's result.
+    The problem is that even for ASCII strings, collation is super complicated!
+    
+        1. Unicode defines Unicode Collation Algorithm (UCA). To perform collation, it uses collation element tables which defines weights on various levels per code point. UCA also offers
+           the Default Unicode Collation Element Table (DUCET). This UCA with DUCET is used when using ICU Root Collator.
+        2. UCA collation consists of rules, which defines how collation works. And ICU locales define customized collations by adding special rules to that.
+        3. UCA behaves differently by using different options.
+    
+    Based on that, our observation is that some of major locales are not defining additional rules in (2). This means that they behaves the same to UCA with DUCET.
+    This patch implements a simplified version of comparison which generates the same results for ASCII strings (excluding control characters) to UCA with DUCET. This fast path can be usable only when the following conditions are met.
+    
+        1. The collator does not have additional rules to ICU Root Colator.
+        2. The collator is using default options.
+    
+    These checks are very important since there are a lot of edge-case locales. For example,
+    
+        1. th (Thai language) ignores punctuations (even including ASCII punctuations) by default. This is defined as ignore-punctuations option is enabled by default, so without (2)'s check, th comparison becomes wrong.
+        2. There are contraction concept (multiple letters behave as a single letter). "ch" letters are ordered interestingly in Czech language. So even in ASCII, Czech shows very interesting collation behavior.
+    
+    So we cannot safely take this fast path without carefully querying the information to ICU.
+    
+    This shows 37% improvement in JetStream2/cdjs in en-US environment.
+    
+    * runtime/IntlCollator.cpp:
+    (JSC::IntlCollator::initializeCollator):
+    (JSC::IntlCollator::compareStrings const):
+    (JSC::canDoASCIIUCADUCETComparisonWithUCollator):
+    (JSC::IntlCollator::updateCanDoASCIIUCADUCETComparison const):
+    (JSC::IntlCollator::checkICULocaleInvariants):
+    * runtime/IntlCollator.h:
+    * runtime/IntlObject.cpp:
+    (JSC::intlCollatorAvailableLocales):
+    * runtime/IntlObject.h:
+    * runtime/IntlObjectInlines.h:
+    (JSC::canUseASCIIUCADUCETComparison):
+    (JSC::compareASCIIWithUCADUCET):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-26  Yusuke Suzuki  <[email protected]>
+
+            [JSC] Add ASCII comparison fast path for IntlCollator
+            https://bugs.webkit.org/show_bug.cgi?id=215798
+
+            Reviewed by Darin Adler, Ross Kirsling, and Saam Barati.
+
+            The idea behind this change is the following: ICU Collator's comparison is too slow. We should have fast path for ASCII strings when we know this equals to ICU Collator's result.
+            The problem is that even for ASCII strings, collation is super complicated!
+
+                1. Unicode defines Unicode Collation Algorithm (UCA). To perform collation, it uses collation element tables which defines weights on various levels per code point. UCA also offers
+                   the Default Unicode Collation Element Table (DUCET). This UCA with DUCET is used when using ICU Root Collator.
+                2. UCA collation consists of rules, which defines how collation works. And ICU locales define customized collations by adding special rules to that.
+                3. UCA behaves differently by using different options.
+
+            Based on that, our observation is that some of major locales are not defining additional rules in (2). This means that they behaves the same to UCA with DUCET.
+            This patch implements a simplified version of comparison which generates the same results for ASCII strings (excluding control characters) to UCA with DUCET. This fast path can be usable only when the following conditions are met.
+
+                1. The collator does not have additional rules to ICU Root Colator.
+                2. The collator is using default options.
+
+            These checks are very important since there are a lot of edge-case locales. For example,
+
+                1. th (Thai language) ignores punctuations (even including ASCII punctuations) by default. This is defined as ignore-punctuations option is enabled by default, so without (2)'s check, th comparison becomes wrong.
+                2. There are contraction concept (multiple letters behave as a single letter). "ch" letters are ordered interestingly in Czech language. So even in ASCII, Czech shows very interesting collation behavior.
+
+            So we cannot safely take this fast path without carefully querying the information to ICU.
+
+            This shows 37% improvement in JetStream2/cdjs in en-US environment.
+
+            * runtime/IntlCollator.cpp:
+            (JSC::IntlCollator::initializeCollator):
+            (JSC::IntlCollator::compareStrings const):
+            (JSC::canDoASCIIUCADUCETComparisonWithUCollator):
+            (JSC::IntlCollator::updateCanDoASCIIUCADUCETComparison const):
+            (JSC::IntlCollator::checkICULocaleInvariants):
+            * runtime/IntlCollator.h:
+            * runtime/IntlObject.cpp:
+            (JSC::intlCollatorAvailableLocales):
+            * runtime/IntlObject.h:
+            * runtime/IntlObjectInlines.h:
+            (JSC::canUseASCIIUCADUCETComparison):
+            (JSC::compareASCIIWithUCADUCET):
+
 2020-08-28  Alan Coon  <[email protected]>
 
         Cherry-pick r266254. rdar://problem/67949890

Modified: branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.cpp (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.cpp	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.cpp	2020-09-02 01:19:17 UTC (rev 266432)
@@ -33,6 +33,7 @@
 #include "JSCInlines.h"
 #include "ObjectConstructor.h"
 #include <unicode/ucol.h>
+#include <wtf/HexNumber.h>
 
 namespace JSC {
 
@@ -271,6 +272,7 @@
         break;
     }
 
+    // Keep in sync with canDoASCIIUCADUCETComparisonSlow about used attributes.
     ucol_setAttribute(m_collator.get(), UCOL_STRENGTH, strength, &status);
     ucol_setAttribute(m_collator.get(), UCOL_CASE_LEVEL, caseLevel, &status);
     ucol_setAttribute(m_collator.get(), UCOL_CASE_FIRST, caseFirst, &status);
@@ -295,24 +297,23 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
 
     UErrorCode status = U_ZERO_ERROR;
-    UCollationResult result = UCOL_EQUAL;
-    if (x.is8Bit() && y.is8Bit() && x.isAllASCII() && y.isAllASCII())
-        result = ucol_strcollUTF8(m_collator.get(), bitwise_cast<const char*>(x.characters8()), x.length(), bitwise_cast<const char*>(y.characters8()), y.length(), &status);
-    else {
-        auto getCharacters = [&] (const StringView& view, Vector<UChar>& buffer) -> const UChar* {
-            if (!view.is8Bit())
-                return view.characters16();
-            buffer.resize(view.length());
-            StringImpl::copyCharacters(buffer.data(), view.characters8(), view.length());
-            return buffer.data();
-        };
+    UCollationResult result = ([&]() -> UCollationResult {
+        if (x.isAllSpecialCharacters<canUseASCIIUCADUCETComparison>() && y.isAllSpecialCharacters<canUseASCIIUCADUCETComparison>()) {
+            if (canDoASCIIUCADUCETComparison()) {
+                if (x.is8Bit() && y.is8Bit())
+                    return compareASCIIWithUCADUCET(x.characters8(), x.length(), y.characters8(), y.length());
+                if (x.is8Bit())
+                    return compareASCIIWithUCADUCET(x.characters8(), x.length(), y.characters16(), y.length());
+                if (y.is8Bit())
+                    return compareASCIIWithUCADUCET(x.characters16(), x.length(), y.characters8(), y.length());
+                return compareASCIIWithUCADUCET(x.characters16(), x.length(), y.characters16(), y.length());
+            }
 
-        Vector<UChar> xBuffer;
-        Vector<UChar> yBuffer;
-        const UChar* xCharacters = getCharacters(x, xBuffer);
-        const UChar* yCharacters = getCharacters(y, yBuffer);
-        result = ucol_strcoll(m_collator.get(), xCharacters, x.length(), yCharacters, y.length());
-    }
+            if (x.is8Bit() && y.is8Bit())
+                return ucol_strcollUTF8(m_collator.get(), bitwise_cast<const char*>(x.characters8()), x.length(), bitwise_cast<const char*>(y.characters8()), y.length(), &status);
+        }
+        return ucol_strcoll(m_collator.get(), x.upconvertedCharacters(), x.length(), y.upconvertedCharacters(), y.length());
+    }());
     if (U_FAILURE(status))
         return throwException(globalObject, scope, createError(globalObject, "Failed to compare strings."_s));
     return jsNumber(result);
@@ -380,4 +381,151 @@
     m_boundCompare.set(vm, this, format);
 }
 
+static bool canDoASCIIUCADUCETComparisonWithUCollator(UCollator& collator)
+{
+    // Attributes are default ones unless we set. So, non-configured attributes are default ones.
+    static constexpr std::pair<UColAttribute, UColAttributeValue> attributes[] = {
+        { UCOL_FRENCH_COLLATION, UCOL_OFF },
+        { UCOL_ALTERNATE_HANDLING, UCOL_NON_IGNORABLE },
+        { UCOL_STRENGTH, UCOL_TERTIARY },
+        { UCOL_CASE_LEVEL, UCOL_OFF },
+        { UCOL_CASE_FIRST, UCOL_OFF },
+        { UCOL_NUMERIC_COLLATION, UCOL_OFF },
+        // We do not check UCOL_NORMALIZATION_MODE status since FCD normalization does nothing for ASCII strings.
+    };
+
+    for (auto& pair : attributes) {
+        UErrorCode status = U_ZERO_ERROR;
+        auto result = ucol_getAttribute(&collator, pair.first, &status);
+        ASSERT(U_SUCCESS(status));
+        if (result != pair.second)
+            return false;
+    }
+
+    // Check existence of tailoring rules. If they do not exist, collation algorithm is UCA DUCET.
+    int32_t length = 0;
+    ucol_getRules(&collator, &length);
+    return !length;
+}
+
+bool IntlCollator::updateCanDoASCIIUCADUCETComparison() const
+{
+    // ICU uses the CLDR root collation order as a default starting point for ordering. (The CLDR root collation is based on the UCA DUCET.)
+    // And customizes this root collation via rules.
+    // The root collation is UCA DUCET and it is code-point comparison if the characters are all ASCII.
+    // http://www.unicode.org/reports/tr10/
+    ASSERT(m_collator);
+    auto checkASCIIUCADUCETComparisonCompatibility = [&] {
+        if (m_usage != Usage::Sort)
+            return false;
+        if (m_collation != "default"_s)
+            return false;
+        if (m_sensitivity != Sensitivity::Variant)
+            return false;
+        if (m_caseFirst != CaseFirst::False)
+            return false;
+        if (m_numeric)
+            return false;
+        if (m_ignorePunctuation)
+            return false;
+        return canDoASCIIUCADUCETComparisonWithUCollator(*m_collator);
+    };
+    bool result = checkASCIIUCADUCETComparisonCompatibility();
+    m_canDoASCIIUCADUCETComparison = triState(result);
+    return result;
+}
+
+#if ASSERT_ENABLED
+void IntlCollator::checkICULocaleInvariants(const HashSet<String>& locales)
+{
+    for (auto& locale : locales) {
+        auto checkASCIIOrderingWithDUCET = [](const String& locale, UCollator& collator) {
+            bool allAreGood = true;
+            for (unsigned x = 0; x < 128; ++x) {
+                for (unsigned y = 0; y < 128; ++y) {
+                    if (canUseASCIIUCADUCETComparison(x) && canUseASCIIUCADUCETComparison(y)) {
+                        UErrorCode status = U_ZERO_ERROR;
+                        UChar xstring[] = { static_cast<UChar>(x), 0 };
+                        UChar ystring[] = { static_cast<UChar>(y), 0 };
+                        auto resultICU = ucol_strcoll(&collator, xstring, 1, ystring, 1);
+                        ASSERT(U_SUCCESS(status));
+                        auto resultJSC = compareASCIIWithUCADUCET(xstring, 1, ystring, 1);
+                        if (resultICU != resultJSC) {
+                            dataLogLn("BAD ", locale, " ", makeString(hex(x)), "(", StringView(xstring, 1), ") <=> ", makeString(hex(y)), "(", StringView(ystring, 1), ") ICU:(", static_cast<int32_t>(resultICU), "),JSC:(", static_cast<int32_t>(resultJSC), ")");
+                            allAreGood = false;
+                        }
+                    }
+                }
+            }
+            return allAreGood;
+        };
+
+        UErrorCode status = U_ZERO_ERROR;
+        auto collator = std::unique_ptr<UCollator, ICUDeleter<ucol_close>>(ucol_open(locale.ascii().data(), &status));
+
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_STRENGTH, UCOL_TERTIARY, &status);
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_CASE_LEVEL, UCOL_OFF, &status);
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_CASE_FIRST, UCOL_OFF, &status);
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_NUMERIC_COLLATION, UCOL_OFF, &status);
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_ALTERNATE_HANDLING, UCOL_DEFAULT, &status);
+        ASSERT(U_SUCCESS(status));
+        ucol_setAttribute(collator.get(), UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+        ASSERT(U_SUCCESS(status));
+
+        if (!canDoASCIIUCADUCETComparisonWithUCollator(*collator))
+            continue;
+
+        // This should not have reorder.
+        int32_t length = ucol_getReorderCodes(collator.get(), nullptr, 0, &status);
+        ASSERT(U_SUCCESS(status));
+        ASSERT(!length);
+
+        // Contractions and Expansions are defined as a rule. If there is no tailoring rule, then they should be UCA DUCET's default.
+
+        auto ensureNotIncludingASCII = [&](USet& set) {
+            Vector<UChar, 32> buffer;
+            for (int32_t index = 0, count = uset_getItemCount(&set); index < count; ++index) {
+                // start and end are inclusive.
+                UChar32 start = 0;
+                UChar32 end = 0;
+                auto status = callBufferProducingFunction(uset_getItem, &set, index, &start, &end, buffer);
+                ASSERT(U_SUCCESS(status));
+                if (buffer.isEmpty()) {
+                    if (isASCII(start)) {
+                        dataLogLn("BAD ", locale, " including ASCII tailored characters");
+                        CRASH();
+                    }
+                } else {
+                    if (StringView(buffer.data(), buffer.size()).isAllASCII()) {
+                        dataLogLn("BAD ", locale, " ", String(buffer.data(), buffer.size()), " including ASCII tailored characters");
+                        CRASH();
+                    }
+                }
+            }
+        };
+
+        auto contractions = std::unique_ptr<USet, ICUDeleter<uset_close>>(uset_openEmpty());
+        auto expansions = std::unique_ptr<USet, ICUDeleter<uset_close>>(uset_openEmpty());
+        ucol_getContractionsAndExpansions(collator.get(), contractions.get(), expansions.get(), true, &status);
+        ASSERT(U_SUCCESS(status));
+
+        ensureNotIncludingASCII(*contractions);
+        ensureNotIncludingASCII(*expansions);
+
+        // This locale should not have tailoring.
+        auto tailored = std::unique_ptr<USet, ICUDeleter<uset_close>>(ucol_getTailoredSet(collator.get(), &status));
+        ensureNotIncludingASCII(*tailored);
+
+        dataLogLnIf(IntlCollatorInternal::verbose, "LOCALE ", locale);
+
+        ASSERT(checkASCIIOrderingWithDUCET(locale, *collator));
+    }
+}
+#endif
+
 } // namespace JSC

Modified: branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.h (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.h	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/runtime/IntlCollator.h	2020-09-02 01:19:17 UTC (rev 266432)
@@ -64,11 +64,26 @@
     JSBoundFunction* boundCompare() const { return m_boundCompare.get(); }
     void setBoundCompare(VM&, JSBoundFunction*);
 
+    bool canDoASCIIUCADUCETComparison() const
+    {
+        if (m_canDoASCIIUCADUCETComparison == TriState::Indeterminate)
+            updateCanDoASCIIUCADUCETComparison();
+        return m_canDoASCIIUCADUCETComparison == TriState::True;
+    }
+
+#if ASSERT_ENABLED
+    static void checkICULocaleInvariants(const HashSet<String>&);
+#else
+    static inline void checkICULocaleInvariants(const HashSet<String>&) { }
+#endif
+
 private:
     IntlCollator(VM&, Structure*);
     void finishCreation(VM&);
     static void visitChildren(JSCell*, SlotVisitor&);
 
+    bool updateCanDoASCIIUCADUCETComparison() const;
+
     static Vector<String> sortLocaleData(const String&, RelevantExtensionKey);
     static Vector<String> searchLocaleData(const String&, RelevantExtensionKey);
 
@@ -92,6 +107,7 @@
     Usage m_usage;
     Sensitivity m_sensitivity;
     CaseFirst m_caseFirst;
+    mutable TriState m_canDoASCIIUCADUCETComparison { TriState::Indeterminate };
     bool m_numeric;
     bool m_ignorePunctuation;
 };

Modified: branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.cpp (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.cpp	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.cpp	2020-09-02 01:19:17 UTC (rev 266432)
@@ -31,6 +31,7 @@
 
 #include "Error.h"
 #include "FunctionPrototype.h"
+#include "IntlCollator.h"
 #include "IntlCollatorConstructor.h"
 #include "IntlCollatorPrototype.h"
 #include "IntlDateTimeFormatConstructor.h"
@@ -261,6 +262,64 @@
     return availableLocales;
 }
 
+// This table is total ordering indexes for ASCII characters in UCA DUCET.
+// It is generated from CLDR common/uca/allkeys_DUCET.txt.
+//
+// Rough overview of UCA is the followings.
+// https://unicode.org/reports/tr10/#Main_Algorithm
+//
+//     1. Normalize each input string.
+//
+//     2. Produce an array of collation elements for each string.
+//
+//         There are 3 (or 4) levels. And each character has 4 weights. We concatenate them into one sequence called collation elements.
+//         For example, "c" has `[.0706.0020.0002]`. And "ca◌́b" becomes `[.0706.0020.0002], [.06D9.0020.0002], [.0000.0021.0002], [.06EE.0020.0002]`
+//         We need to consider variable weighting (https://unicode.org/reports/tr10/#Variable_Weighting), but if it is Non-ignorable, we can just use
+//         the collation elements defined in the table.
+//
+//     3. Produce a sort key for each string from the arrays of collation elements.
+//
+//         Generate sort key from collation elements. From lower levels to higher levels, we collect weights. But 0000 weight is skipped.
+//         Between levels, we insert 0000 weight if the boundary.
+//
+//             string: "ca◌́b"
+//             collation elements: `[.0706.0020.0002], [.06D9.0020.0002], [.0000.0021.0002], [.06EE.0020.0002]`
+//             sort key: `0706 06D9 06EE 0000 0020 0020 0021 0020 0000 0002 0002 0002 0002`
+//                                        ^                        ^
+//                                        level boundary           level boundary
+//
+//     4. Compare the two sort keys with a binary comparison operation.
+//
+// Key observations are the followings.
+//
+//     1. If an input is an ASCII string, UCA step-1 normalization does nothing.
+//     2. If an input is an ASCII string, non-starters (https://unicode.org/reports/tr10/#UTS10-D33) does not exist. So no special handling in UCA step-2 is required.
+//     3. If an input is an ASCII string, no multiple character collation elements exist. So no special handling in UCA step-2 is required. For example, "L·" is not ASCII.
+//     4. UCA step-3 handles 0000 weighted characters specially. And ASCII contains these characters. But 0000 elements are used only for rare control characters.
+//        We can ignore this special handling if ASCII strings do not include control characters.
+//     5. Except 0000 cases, all characters' level-1 weights are different. And level-2 weights are always 0020, which is lower than any level-1 weights.
+//        This means that binary comparison in UCA step-4 do not need to check level 2~ weights.
+//
+//  Based on the above observation, our fast path handles ASCII strings excluding control characters. The following weight is recomputed weights from level-1 weights.
+const uint8_t ducetWeights[128] = {
+    0, 0, 0, 0, 0, 0, 0, 0,
+    0, 1, 2, 3, 4, 5, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0,
+    6, 12, 16, 28, 38, 29, 27, 15,
+    17, 18, 24, 32, 9, 8, 14, 25,
+    39, 40, 41, 42, 43, 44, 45, 46,
+    47, 48, 11, 10, 33, 34, 35, 13,
+    23, 50, 52, 54, 56, 58, 60, 62,
+    64, 66, 68, 70, 72, 74, 76, 78,
+    80, 82, 84, 86, 88, 90, 92, 94,
+    96, 98, 100, 19, 26, 20, 31, 7,
+    30, 49, 51, 53, 55, 57, 59, 61,
+    63, 65, 67, 69, 71, 73, 75, 77,
+    79, 81, 83, 85, 87, 89, 91, 93,
+    95, 97, 99, 21, 36, 22, 37, 0,
+};
+
 const HashSet<String>& intlCollatorAvailableLocales()
 {
     static LazyNeverDestroyed<HashSet<String>> availableLocales;
@@ -277,6 +336,7 @@
             availableLocales->add(locale);
             addScriptlessLocaleIfNeeded(availableLocales.get(), locale);
         }
+        IntlCollator::checkICULocaleInvariants(availableLocales.get());
     });
     return availableLocales;
 }

Modified: branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.h (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.h	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObject.h	2020-09-02 01:19:17 UTC (rev 266432)
@@ -34,6 +34,8 @@
 
 namespace JSC {
 
+extern const uint8_t ducetWeights[128];
+
 enum class LocaleMatcher : uint8_t {
     Lookup,
     BestFit,

Modified: branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObjectInlines.h (266431 => 266432)


--- branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObjectInlines.h	2020-09-02 01:19:14 UTC (rev 266431)
+++ branches/safari-610-branch/Source/_javascript_Core/runtime/IntlObjectInlines.h	2020-09-02 01:19:17 UTC (rev 266432)
@@ -29,6 +29,7 @@
 #include "BuiltinNames.h"
 #include "IntlObject.h"
 #include "JSObject.h"
+#include <unicode/ucol.h>
 
 namespace JSC {
 
@@ -116,4 +117,31 @@
     return fallback;
 }
 
+
+ALWAYS_INLINE bool canUseASCIIUCADUCETComparison(UChar character)
+{
+    return isASCII(character) && ducetWeights[character];
+}
+
+template<typename CharacterType1, typename CharacterType2>
+inline UCollationResult compareASCIIWithUCADUCET(const CharacterType1* characters1, unsigned length1, const CharacterType2* characters2, unsigned length2)
+{
+    unsigned commonLength = std::min(length1, length2);
+    for (unsigned position = 0; position < commonLength; ++position) {
+        auto lhs = characters1[position];
+        auto rhs = characters2[position];
+        ASSERT(canUseASCIIUCADUCETComparison(lhs));
+        ASSERT(canUseASCIIUCADUCETComparison(rhs));
+        uint8_t leftWeight = ducetWeights[lhs];
+        uint8_t rightWeight = ducetWeights[rhs];
+        if (leftWeight == rightWeight)
+            continue;
+        return leftWeight > rightWeight ? UCOL_GREATER : UCOL_LESS;
+    }
+
+    if (length1 == length2)
+        return UCOL_EQUAL;
+    return length1 > length2 ? UCOL_GREATER : UCOL_LESS;
+}
+
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to