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-22991 Reduce Calendar object size #3327

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

FrankYFTang
Copy link
Contributor

@FrankYFTang FrankYFTang commented Jan 7, 2025

Gregorian monthOfYear, dayOfMonth only need one byte dayOfYear only need two bytes to store.
These fields are used to store calculated value of day of year, day of month and month of year according to Gregorian calendar, and therefore will max to 365, 31 and 12 so it is a waste to store them with 4 bytes. We only need 9 bits, 5 bits, 4 bits for them. We can use bit fields to store but still need 18 bits which is more than 2 bytes. In this PR, I change to use 2 + 1 + 1 = 4 bytes to store them. Save 8 bytes per Calendar object

Checklist

  • Required: Issue filed: ICU-22991
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • 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

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • icu4c/source/i18n/calendar.cpp is different
  • icu4c/source/i18n/unicode/calendar.h is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

@markusicu markusicu self-assigned this Jan 7, 2025
Copy link
Member

@markusicu markusicu left a comment

Choose a reason for hiding this comment

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

optional: Java?

icu4c/source/i18n/calendar.cpp Outdated Show resolved Hide resolved
icu4c/source/i18n/calendar.cpp Outdated Show resolved Hide resolved
richgillam
richgillam previously approved these changes Jan 7, 2025
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 fine to me. I second both of Markus's comments, but have none of my own to add.

@FrankYFTang
Copy link
Contributor Author

PTAL

Copy link
Member

@markusicu markusicu left a comment

Choose a reason for hiding this comment

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

Whoa! I guess I need to be careful what I ask for... I glanced at many of the changes, and they look plausible, and it looks like you are reducing the amount of work and reducing unused variables. I am stamping.

As for Java, I suspect that it might matter less there whether we store byte/short vs. int, but it might be nice to port the other changes there if they make sense. (Don't know what the Grego functions look like there since Java does not have output reference types.)

@richgillam ok?

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.

Looked at it again. LGTM.

@jira-pull-request-webhook
Copy link

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

@FrankYFTang
Copy link
Contributor Author

optional: Java?

I will deal with that in a separate PR later.

@FrankYFTang FrankYFTang merged commit 9eafd8c into unicode-org:main Jan 8, 2025
94 checks passed
@FrankYFTang FrankYFTang deleted the ICU-22991 branch January 8, 2025 20:26
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.

3 participants