Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU-22950 Do not initialize currency for NumberPropertyMapper when useCurrency is false #3250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nightelf3
Copy link

resolveCurrency() slows down simple number formatting requests like:

for (int i = 0; i < 9999; i++)
  u_snprintf_u(buff, 100, u"%d", i);

Since icu4c doesn't use currency there, we can skip its initialization.

Checklist

  • Required: Issue filed: https://unicode-org.atlassian.net/browse/ICU-22950
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Required: The PR description must include the link to the Jira Issue, for example by completing the URL in the first checklist item
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

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 it's initialization.
@CLAassistant
Copy link

CLAassistant commented Oct 21, 2024

CLA assistant check
All committers have signed the CLA.

eggrobin
eggrobin previously approved these changes Oct 24, 2024
Comment on lines +77 to +78
CurrencyUnit currency;
UCurrencyUsage currencyUsage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expanded the rest of this (long) function, searched for "currency", and found some code that uses these variables but is gated by conditions other than useCurrency.

  • if (!properties.currencyUsage.isNull())
  • if (exportedProperties != nullptr)

If we think we can guarantee that useCurrency is true there, then we should add U_ASSERT(useCurrency) there.
For the second one, maybe a default-constructed currency is fine if not useCurrency?
Otherwise, we may need to add a runtime check for useCurrency.

@sffc @mihnita @richgillam @eggrobin

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markus is right; this is a concern.

For if (!properties.currencyUsage.isNull()), I wonder if this could just be changed to useCurrency?

For exportedProperties->currency, I agree that a default-constructed currency ought to be fine.

For if (precision.fType == Precision::PrecisionType::RND_CURRENCY), I wonder if we could change this to if (useCurrency && precision.fType == Precision::PrecisionType::RND_CURRENCY)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an assertion to if (!properties.currencyUsage.isNull()), since useCurrency is true when !properties.currencyUsage.isNull()
Used if (useCurrency && precision.fType == Precision::PrecisionType::RND_CURRENCY), thank you!

Copy link
Contributor

@richgillam richgillam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants