Bug 1370194 - Prefer to use Array objects when performing array operations in Intl self-hosted code. r=till
authorAndré Bargull <andre.bargull@gmail.com>
Mon, 05 Jun 2017 13:27:36 +0200
changeset 410710 d912b21f2ae6479ed294917909f0cfcbdcc0208a
parent 410709 1e14ae1885dcbad2241c59cb08152c16c62532a7
child 410711 dbedc1b9a3cc6924c6ffbab4b85045aca8712054
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1370194
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1370194 - Prefer to use Array objects when performing array operations in Intl self-hosted code. r=till
js/src/builtin/Intl.js
--- a/js/src/builtin/Intl.js
+++ b/js/src/builtin/Intl.js
@@ -431,28 +431,34 @@ function CanonicalizeLanguageTag(locale)
             if (i === 1 && extlangMappings[subtag].prefix === subtags[0]) {
                 callFunction(std_Array_shift, subtags);
                 i--;
             }
         }
         subtags[i] = subtag;
         i++;
     }
+
+    // Directly return when the language tag doesn't contain any extension or
+    // private use sub-tags.
+    if (i === subtags.length)
+        return callFunction(std_Array_join, subtags, "-");
+
     var normal = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, 0, i), "-");
 
     // Extension sequences are sorted by their singleton characters.
     // "u-ca-chinese-t-zh-latn" -> "t-zh-latn-u-ca-chinese"
-    var extensions = new List();
+    var extensions = [];
     while (i < subtags.length && subtags[i] !== "x") {
         var extensionStart = i;
         i++;
         while (i < subtags.length && subtags[i].length > 1)
             i++;
         var extension = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, extensionStart, i), "-");
-        callFunction(std_Array_push, extensions, extension);
+        _DefineDataProperty(extensions, extensions.length, extension);
     }
     callFunction(std_Array_sort, extensions);
 
     // Private use sequences are left as is. "x-private"
     var privateUse = "";
     if (i < subtags.length)
         privateUse = callFunction(std_Array_join, callFunction(std_Array_slice, subtags, i), "-");
 
@@ -801,36 +807,39 @@ function addSpecialMissingLanguageTags(a
 
 /**
  * Canonicalizes a locale list.
  *
  * Spec: ECMAScript Internationalization API Specification, 9.2.1.
  */
 function CanonicalizeLocaleList(locales) {
     if (locales === undefined)
-        return new List();
-    var seen = new List();
-    if (typeof locales === "string")
-        locales = [locales];
+        return [];
+    if (typeof locales === "string") {
+        if (!IsStructurallyValidLanguageTag(locales))
+            ThrowRangeError(JSMSG_INVALID_LANGUAGE_TAG, locales);
+        return [CanonicalizeLanguageTag(locales)];
+    }
+    var seen = [];
     var O = ToObject(locales);
     var len = ToLength(O.length);
     var k = 0;
     while (k < len) {
         // Don't call ToString(k) - SpiderMonkey is faster with integers.
         var kPresent = HasProperty(O, k);
         if (kPresent) {
             var kValue = O[k];
             if (!(typeof kValue === "string" || IsObject(kValue)))
                 ThrowTypeError(JSMSG_INVALID_LOCALES_ELEMENT);
             var tag = ToString(kValue);
             if (!IsStructurallyValidLanguageTag(tag))
                 ThrowRangeError(JSMSG_INVALID_LANGUAGE_TAG, tag);
             tag = CanonicalizeLanguageTag(tag);
             if (callFunction(ArrayIndexOf, seen, tag) === -1)
-                callFunction(std_Array_push, seen, tag);
+                _DefineDataProperty(seen, seen.length, tag);
         }
         k++;
     }
     return seen;
 }
 
 
 function BestAvailableLocaleHelper(availableLocales, locale, considerDefaultLocale) {
@@ -1176,36 +1185,36 @@ function ResolveLocale(availableLocales,
  * matching (possibly fallback) locale. Locales appear in the same order in the
  * returned list as in the input list.
  *
  * Spec: ECMAScript Internationalization API Specification, 9.2.6.
  */
 function LookupSupportedLocales(availableLocales, requestedLocales) {
     // Steps 1-2.
     var len = requestedLocales.length;
-    var subset = new List();
+    var subset = [];
 
     // Steps 3-4.
     var k = 0;
     while (k < len) {
         // Steps 4.a-b.
         var locale = requestedLocales[k];
         var noExtensionsLocale = removeUnicodeExtensions(locale);
 
         // Step 4.c-d.
         var availableLocale = BestAvailableLocale(availableLocales, noExtensionsLocale);
         if (availableLocale !== undefined)
-            callFunction(std_Array_push, subset, locale);
+            _DefineDataProperty(subset, subset.length, locale);
 
         // Step 4.e.
         k++;
     }
 
     // Steps 5-6.
-    return callFunction(std_Array_slice, subset, 0);
+    return subset;
 }
 
 
 /**
  * Returns the subset of requestedLocales for which availableLocales has a
  * matching (possibly fallback) locale. Locales appear in the same order in the
  * returned list as in the input list.
  *
@@ -3433,26 +3442,18 @@ function Intl_PluralRules_resolvedOption
 
 
 /**
  * 8.2.1 Intl.getCanonicalLocales ( locales )
  *
  * ES2017 Intl draft rev 947aa9a0c853422824a0c9510d8f09be3eb416b9
  */
 function Intl_getCanonicalLocales(locales) {
-    // Step 1.
-    var localeList = CanonicalizeLocaleList(locales);
-
-    // Step 2 (Inlined CreateArrayFromList).
-    var array = [];
-
-    for (var n = 0, len = localeList.length; n < len; n++)
-        _DefineDataProperty(array, n, localeList[n]);
-
-    return array;
+    // Steps 1-2.
+    return CanonicalizeLocaleList(locales);
 }
 
 /**
  * This function is a custom function in the style of the standard Intl.*
  * functions, that isn't part of any spec or proposal yet.
  *
  * Returns an object with the following properties:
  *   locale: