haikuwebkit/JSTests/stress/ducet-level-3-or-4-comparis...

19 lines
719 B
JavaScript
Raw Permalink Normal View History

[JSC] DUCET level-1 weighs are equal if characters are alphabets https://bugs.webkit.org/show_bug.cgi?id=224047 Reviewed by Saam Barati and Mark Lam. JSTests: * stress/ducet-level-3-or-4-comparison.js: Added. (shouldBe): Source/JavaScriptCore: ASCII comparison optimization was based on that DUCET level-1 weights are all different (except for 0000 case), but this was wrong. If we have the same latin letters with different capitalization, then they have the same level-1 weight ('A' v.s. 'a'). In this patch, 1. If we found that the result of level-1 weight comparison is equal, and characters are not equal, then we do level-3 weight comparison. We do not perform level-2 since they are all the same weight in ASCII (excluding control characters) region. 2. We do not perform level-4 weight comparison since level-1 and level-3 comparison must distinguish the strings. Level-1 weights are equal only when characters are the same latin letters. And level-3 weight puts different weights for capital latin letters. Since we already know that these strings are different while they are equal in level-1 weight comparison, the only case is that they have same latin letters in the same position. In that case, level-3 weight must say different results for these characters so that we never meet "equal" status in level-3 weight comparison if characters are different. * runtime/IntlObject.cpp: * runtime/IntlObject.h: * runtime/IntlObjectInlines.h: (JSC::canUseASCIIUCADUCETComparison): (JSC::compareASCIIWithUCADUCETLevel3): (JSC::compareASCIIWithUCADUCET): Canonical link: https://commits.webkit.org/236289@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275653 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-08 05:48:03 +00:00
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var collator = new Intl.Collator('en-US');
shouldBe(collator.compare("ABC", "ABD Ã"), -1);
shouldBe(collator.compare("ABD Ã", "AbE"), -1);
shouldBe(collator.compare("AbE", "ABC"), 1);
shouldBe(collator.compare("ABC", "abc"), 1);
shouldBe(collator.compare("ABC", "ABC"), 0);
shouldBe(collator.compare("abc", "abc"), 0);
shouldBe(collator.compare("abc", "abC"), -1);
shouldBe(collator.compare("AB - AS Foobar", "AB - AS Pulheim Käther"), -1);
shouldBe(collator.compare("AB - AS Pulheim Käther", "Abz - Baz Qux"), -1);
shouldBe(collator.compare("Abz - Baz Qux", "AB - AS Foobar"), 1);