ICU-22950 Do not initialize currency redundantly

resolveCurrency() slows down simple number formatting requests like:
for (int i = 0; i < 9999; i++) u_snprintf_u(buff, 100, u"%d", i);
Since we don't use currency here, we can skip its initialization.
This commit is contained in:
Vladyslav Yeremeichuk 2024-10-21 21:01:40 +03:00 committed by Markus Scherer
parent bbaa68419b
commit 624a26030b

View file

@ -74,9 +74,11 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
!properties.currencyPluralInfo.fPtr.isNull() ||
!properties.currencyUsage.isNull() ||
warehouse.affixProvider.get().hasCurrencySign());
CurrencyUnit currency = resolveCurrency(properties, locale, status);
UCurrencyUsage currencyUsage = properties.currencyUsage.getOrDefault(UCURR_USAGE_STANDARD);
CurrencyUnit currency;
UCurrencyUsage currencyUsage;
if (useCurrency) {
currency = resolveCurrency(properties, locale, status);
currencyUsage = properties.currencyUsage.getOrDefault(UCURR_USAGE_STANDARD);
// NOTE: Slicing is OK.
macros.unit = currency; // NOLINT
}
@ -129,6 +131,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
}
Precision precision;
if (!properties.currencyUsage.isNull()) {
U_ASSERT(useCurrency);
precision = Precision::constructCurrency(currencyUsage).withCurrency(currency);
} else if (roundingIncrement != 0.0) {
if (PatternStringUtils::ignoreRoundingIncrement(roundingIncrement, maxFrac)) {
@ -276,7 +279,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
exportedProperties->maximumIntegerDigits = maxInt == -1 ? INT32_MAX : maxInt;
Precision rounding_;
if (precision.fType == Precision::PrecisionType::RND_CURRENCY) {
if (useCurrency && precision.fType == Precision::PrecisionType::RND_CURRENCY) {
rounding_ = precision.withCurrency(currency, status);
} else {
rounding_ = precision;