Skip to content

Commit

Permalink
ICU-22991 Reduce Calendar object size
Browse files Browse the repository at this point in the history
Gregorian monthOfYear, dayOfMonth only need one byte
dayOfYear only need two bytes to store.
  • Loading branch information
FrankYFTang committed Jan 7, 2025
1 parent a8d9f47 commit 7d58c2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions icu4c/source/i18n/calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,9 +1530,16 @@ void Calendar::computeGregorianFields(int32_t julianDay, UErrorCode& ec) {
ec = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
Grego::dayToFields(julianDay, fGregorianYear, fGregorianMonth,
fGregorianDayOfMonth, gregorianDayOfWeekUnused,
fGregorianDayOfYear, ec);
int32_t gregorianMonth, gregorianDayOfMonth, gregorianDayOfYear;
Grego::dayToFields(julianDay, fGregorianYear, gregorianMonth,
gregorianDayOfMonth, gregorianDayOfWeekUnused,
gregorianDayOfYear, ec);
U_ASSERT(gregorianMonth <= 12);
U_ASSERT(gregorianDayOfMonth <= 31);
U_ASSERT(gregorianDayOfYear <= 366);
fGregorianMonth = gregorianMonth;
fGregorianDayOfMonth = gregorianDayOfMonth;
fGregorianDayOfYear = gregorianDayOfYear;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions icu4c/source/i18n/unicode/calendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -2257,21 +2257,21 @@ class U_I18N_API Calendar : public UObject {
* returned by getGregorianMonth().
* @see #computeGregorianFields
*/
int32_t fGregorianMonth;
int8_t fGregorianMonth;

/**
* The Gregorian day of the year, as computed by
* computeGregorianFields() and returned by getGregorianDayOfYear().
* The Gregorian day of the month, as computed by
* computeGregorianFields() and returned by getGregorianDayOfMonth().
* @see #computeGregorianFields
*/
int32_t fGregorianDayOfYear;
int8_t fGregorianDayOfMonth;

/**
* The Gregorian day of the month, as computed by
* computeGregorianFields() and returned by getGregorianDayOfMonth().
* The Gregorian day of the year, as computed by
* computeGregorianFields() and returned by getGregorianDayOfYear().
* @see #computeGregorianFields
*/
int32_t fGregorianDayOfMonth;
int16_t fGregorianDayOfYear;

/* calculations */

Expand Down

0 comments on commit 7d58c2e

Please sign in to comment.