Bug 1719747 - Part 2: Use NewDenseFullyAllocatedArray. r=anba
authorYoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Thu, 09 Sep 2021 12:02:21 +0000
changeset 591505 1aa6a3fcd6327639c86bc1bacfcbb90a95d10845
parent 591504 a83961b4491cef7a34cea95ac2122c75ec9dfe43
child 591506 0433a2711b0a02f9b1b282b52324b84476b3cb4f
push id149451
push userallstars.chh@gmail.com
push dateThu, 09 Sep 2021 12:04:55 +0000
treeherderautoland@0433a2711b0a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersanba
bugs1719747
milestone94.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 1719747 - Part 2: Use NewDenseFullyAllocatedArray. r=anba Differential Revision: https://phabricator.services.mozilla.com/D123165
js/src/builtin/intl/ListFormat.cpp
--- a/js/src/builtin/intl/ListFormat.cpp
+++ b/js/src/builtin/intl/ListFormat.cpp
@@ -245,24 +245,27 @@ static bool FormatListToParts(JSContext*
                               MutableHandleValue result) {
   mozilla::intl::ListFormat::PartVector parts;
   auto formatResult = lf->FormatToParts(list, parts);
   if (formatResult.isErr()) {
     js::intl::ReportInternalError(cx, formatResult.unwrapErr());
     return false;
   }
 
-  RootedArrayObject partsArray(cx, NewDenseEmptyArray(cx));
+  RootedArrayObject partsArray(cx,
+                               NewDenseFullyAllocatedArray(cx, parts.length()));
   if (!partsArray) {
     return false;
   }
+  partsArray->ensureDenseInitializedLength(0, parts.length());
 
   RootedObject singlePart(cx);
   RootedValue val(cx);
 
+  size_t index = 0;
   for (const mozilla::intl::ListFormat::Part& part : parts) {
     singlePart = NewPlainObject(cx);
     if (!singlePart) {
       return false;
     }
 
     if (part.first == mozilla::intl::ListFormat::PartType::Element) {
       val = StringValue(cx->names().element);
@@ -279,20 +282,19 @@ static bool FormatListToParts(JSContext*
     if (!partStr) {
       return false;
     }
     val = StringValue(partStr);
     if (!DefineDataProperty(cx, singlePart, cx->names().value, val)) {
       return false;
     }
 
-    if (!NewbornArrayPush(cx, partsArray, ObjectValue(*singlePart))) {
-      return false;
-    }
+    partsArray->initDenseElement(index++, ObjectValue(*singlePart));
   }
+  MOZ_ASSERT(index == parts.length());
 
   result.setObject(*partsArray);
   return true;
 }
 
 bool js::intl_FormatList(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
   MOZ_ASSERT(args.length() == 3);