Commit f75c90a6 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Move NumberFormat to LocalizedNumberFormatter

Speed up Intl.PluralRules constructor x3.4

$python -u tools/run_perf.py --binary-override-path  \
   out/x64.release/d8 --filter "JSTests/Intl" \
   test/js-perf-test/JSTests5.json

Score for NewIntlPluralRules
BEFORE  550  581  576
AFTER  1856 1978 1996


Bug: v8:9300
Change-Id: I76b4290aa433b1049e3ee770d391b86e468e967d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1630134
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61924}
parent b179dd83
......@@ -2167,7 +2167,7 @@ void JSPluralRules::JSPluralRulesPrint(std::ostream& os) { // NOLINT
os << "\n - locale: " << Brief(locale());
os << "\n - type: " << TypeAsString();
os << "\n - icu plural rules: " << Brief(icu_plural_rules());
os << "\n - icu decimal format: " << Brief(icu_decimal_format());
os << "\n - icu_number_formatter: " << Brief(icu_number_formatter());
JSObjectPrintBody(os, *this);
}
......
......@@ -34,6 +34,7 @@
#include "unicode/formattedvalue.h"
#include "unicode/locid.h"
#include "unicode/normalizer2.h"
#include "unicode/numberformatter.h"
#include "unicode/numfmt.h"
#include "unicode/numsys.h"
#include "unicode/timezone.h"
......
......@@ -38,7 +38,8 @@ extern class JSPluralRules extends JSObject {
locale: String;
flags: Smi;
icu_plural_rules: Foreign; // Managed<icu::PluralRules>
icu_decimal_format: Foreign; // Managed<icu::DecimalFormat>
icu_number_formatter:
Foreign; // Managed<icu::number::LocalizedNumberFormatter>
}
extern class JSRelativeTimeFormat extends JSObject {
......
......@@ -485,6 +485,8 @@ Handle<String> SignDisplayString(Isolate* isolate,
return ReadOnlyRoots(isolate).auto_string_handle();
}
} // anonymous namespace
// Return the minimum integer digits by counting the number of '0' after
// "integer-width/+" in the skeleton.
// Ex: Return 15 for skeleton as
......@@ -492,7 +494,8 @@ Handle<String> SignDisplayString(Isolate* isolate,
// 1
// 123456789012345
// Return default value as 1 if there are no "integer-width/+".
int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString& skeleton) {
int32_t JSNumberFormat::MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton) {
// count the number of 0 after "integer-width/+"
icu::UnicodeString search("integer-width/+");
int32_t index = skeleton.indexOf(search);
......@@ -515,8 +518,8 @@ int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString& skeleton) {
// 123
// 4567
// Set The minimum as 3 and maximum as 7.
bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum) {
bool JSNumberFormat::FractionDigitsFromSkeleton(
const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) {
icu::UnicodeString search(".");
int32_t index = skeleton.indexOf(search);
if (index < 0) return false;
......@@ -542,8 +545,8 @@ bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
// 12345
// 6789012
// Set The minimum as 5 and maximum as 12.
bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum) {
bool JSNumberFormat::SignificantDigitsFromSkeleton(
const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) {
icu::UnicodeString search("@");
int32_t index = skeleton.indexOf(search);
if (index < 0) return false;
......@@ -561,6 +564,8 @@ bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
return true;
}
namespace {
// Ex: percent .### rounding-mode-half-up
// Special case for "percent"
// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .###
......@@ -642,9 +647,6 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
icu::UnicodeString skeleton = icu_number_formatter->toSkeleton(status);
CHECK(U_SUCCESS(status));
std::string s_str;
s_str = skeleton.toUTF8String<std::string>(s_str);
// 4. Let options be ! ObjectCreate(%ObjectPrototype%).
Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
......
......@@ -17,14 +17,15 @@
#include "src/objects/intl-objects.h"
#include "src/objects/managed.h"
#include "src/objects/objects.h"
#include "unicode/numberformatter.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace U_ICU_NAMESPACE {
class NumberFormat;
class UnicodeString;
namespace number {
class LocalizedNumberFormatter;
} // namespace number
} // namespace U_ICU_NAMESPACE
namespace v8 {
......@@ -56,6 +57,13 @@ class JSNumberFormat : public JSObject {
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
static int32_t MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton);
static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum);
static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum);
DECL_CAST(JSNumberFormat)
DECL_PRINTER(JSNumberFormat)
DECL_VERIFIER(JSNumberFormat)
......
......@@ -25,8 +25,9 @@ ACCESSORS(JSPluralRules, locale, String, kLocaleOffset)
SMI_ACCESSORS(JSPluralRules, flags, kFlagsOffset)
ACCESSORS(JSPluralRules, icu_plural_rules, Managed<icu::PluralRules>,
kIcuPluralRulesOffset)
ACCESSORS(JSPluralRules, icu_decimal_format, Managed<icu::DecimalFormat>,
kIcuDecimalFormatOffset)
ACCESSORS(JSPluralRules, icu_number_formatter,
Managed<icu::number::LocalizedNumberFormatter>,
kIcuNumberFormatterOffset)
inline void JSPluralRules::set_type(Type type) {
DCHECK_LT(type, Type::COUNT);
......
This diff is collapsed.
......@@ -22,8 +22,10 @@
#include "src/objects/object-macros.h"
namespace U_ICU_NAMESPACE {
class DecimalFormat;
class PluralRules;
namespace number {
class LocalizedNumberFormatter;
} // namespace number
} // namespace U_ICU_NAMESPACE
namespace v8 {
......@@ -76,7 +78,8 @@ class JSPluralRules : public JSObject {
DECL_ACCESSORS(locale, String)
DECL_INT_ACCESSORS(flags)
DECL_ACCESSORS(icu_plural_rules, Managed<icu::PluralRules>)
DECL_ACCESSORS(icu_decimal_format, Managed<icu::DecimalFormat>)
DECL_ACCESSORS(icu_number_formatter,
Managed<icu::number::LocalizedNumberFormatter>)
OBJECT_CONSTRUCTORS(JSPluralRules, JSObject);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment