Bug 1610514 - Part 2: Move GetFieldTypeForNumberField out of NumberFormatFields::append. r=jwalden
authorAndré Bargull <andre.bargull@gmail.com>
Thu, 30 Jan 2020 08:31:35 +0000
changeset 512114 177fd2d58046b31fd9d212446f0ed6252fa398d0
parent 512113 4f0bdc386a8563f0b36d64b234397e2b07e17f5b
child 512115 236b8297fd5d66bebcb478e4dffe5ad7d2376a4b
push id37072
push usercsabou@mozilla.com
push dateThu, 30 Jan 2020 15:44:43 +0000
treeherdermozilla-central@f97c48da9cee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1610514
milestone74.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 1610514 - Part 2: Move GetFieldTypeForNumberField out of NumberFormatFields::append. r=jwalden Moving GetFieldTypeForNumberField outside of NumberFormatFields::append let's us avoid adding another flag to NumberFormatFields in the next part. Differential Revision: https://phabricator.services.mozilla.com/D60968
js/src/builtin/intl/NumberFormat.cpp
--- a/js/src/builtin/intl/NumberFormat.cpp
+++ b/js/src/builtin/intl/NumberFormat.cpp
@@ -1097,36 +1097,32 @@ struct Field {
   Field(uint32_t begin, uint32_t end, FieldType type)
       : begin(begin), end(end), type(type) {}
 };
 
 class NumberFormatFields {
   using FieldsVector = Vector<Field, 16>;
 
   FieldsVector fields_;
-  HandleValue number_;
 
  public:
-  NumberFormatFields(JSContext* cx, HandleValue number)
-      : fields_(cx), number_(number) {}
+  explicit NumberFormatFields(JSContext* cx) : fields_(cx) {}
 
-  MOZ_MUST_USE bool append(int32_t field, int32_t begin, int32_t end);
+  MOZ_MUST_USE bool append(FieldType type, int32_t begin, int32_t end);
 
   MOZ_MUST_USE ArrayObject* toArray(JSContext* cx,
                                     JS::HandleString overallResult,
                                     FieldType unitType);
 };
 
-bool NumberFormatFields::append(int32_t field, int32_t begin, int32_t end) {
+bool NumberFormatFields::append(FieldType type, int32_t begin, int32_t end) {
   MOZ_ASSERT(begin >= 0);
   MOZ_ASSERT(end >= 0);
   MOZ_ASSERT(begin < end, "erm, aren't fields always non-empty?");
 
-  FieldType type =
-      GetFieldTypeForNumberField(UNumberFormatFields(field), number_);
   return fields_.emplaceBack(uint32_t(begin), uint32_t(end), type);
 }
 
 ArrayObject* NumberFormatFields::toArray(JSContext* cx,
                                          HandleString overallResult,
                                          FieldType unitType) {
   // Merge sort the fields vector.  Expand the vector to have scratch space for
   // performing the sort.
@@ -1442,17 +1438,17 @@ static bool FormattedNumberToParts(JSCon
   ucfpos_constrainCategory(fpos, UFIELD_CATEGORY_NUMBER, &status);
   if (U_FAILURE(status)) {
     intl::ReportInternalError(cx);
     return false;
   }
 
   // Vacuum up fields in the overall formatted string.
 
-  NumberFormatFields fields(cx, number);
+  NumberFormatFields fields(cx);
 
   while (true) {
     bool hasMore = ufmtval_nextPosition(formattedValue, fpos, &status);
     if (U_FAILURE(status)) {
       intl::ReportInternalError(cx);
       return false;
     }
     if (!hasMore) {
@@ -1467,17 +1463,20 @@ static bool FormattedNumberToParts(JSCon
 
     int32_t beginIndex, endIndex;
     ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status);
     if (U_FAILURE(status)) {
       intl::ReportInternalError(cx);
       return false;
     }
 
-    if (!fields.append(field, beginIndex, endIndex)) {
+    FieldType type =
+        GetFieldTypeForNumberField(UNumberFormatFields(field), number);
+
+    if (!fields.append(type, beginIndex, endIndex)) {
       return false;
     }
   }
 
   ArrayObject* array = fields.toArray(cx, overallResult, relativeTimeUnit);
   if (!array) {
     return false;
   }