From b31ce36a7d60a398ab92a9f18746d14a3e0ef2e1 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 30 Dec 2024 20:33:10 -0800 Subject: [PATCH] ICU-22991 Reduce fStamp to 8 bits Reduce 24x3=72 bytes per Calendar object by changing from 32 bits integer to 8 bits integer for the stamp array. Reset the fNextStamp inside the clear function. fix --- icu4c/source/i18n/calendar.cpp | 26 ++++++++----------- icu4c/source/i18n/unicode/calendar.h | 6 ++--- .../main/java/com/ibm/icu/util/Calendar.java | 16 +++++++----- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index ca3de520c8f2..0a02c33f0d85 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -156,7 +156,7 @@ U_CFUNC void ucal_dump(UCalendar* cal) { #endif /* Max value for stamp allowable before recalculation */ -#define STAMP_MAX 10000 +#define STAMP_MAX 127 static const char * const gCalTypes[] = { "gregorian", @@ -700,7 +700,7 @@ fIsTimeSet(false), fAreFieldsSet(false), fAreAllFieldsSet(false), fAreFieldsVirtuallySet(false), -fNextStamp(static_cast(kMinimumUserStamp)), +fNextStamp(kMinimumUserStamp), fTime(0), fLenient(true), fZone(nullptr), @@ -728,7 +728,7 @@ fIsTimeSet(false), fAreFieldsSet(false), fAreAllFieldsSet(false), fAreFieldsVirtuallySet(false), -fNextStamp(static_cast(kMinimumUserStamp)), +fNextStamp(kMinimumUserStamp), fTime(0), fLenient(true), fZone(nullptr), @@ -763,7 +763,7 @@ fIsTimeSet(false), fAreFieldsSet(false), fAreAllFieldsSet(false), fAreFieldsVirtuallySet(false), -fNextStamp(static_cast(kMinimumUserStamp)), +fNextStamp(kMinimumUserStamp), fTime(0), fLenient(true), fZone(nullptr), @@ -1166,12 +1166,9 @@ Calendar::setTimeInMillis( double millis, UErrorCode& status ) { fAreFieldsSet = fAreAllFieldsSet = false; fIsTimeSet = fAreFieldsVirtuallySet = true; - for (int32_t i=0; istamp[], an internal array. * @serial */ - private transient int nextStamp = MINIMUM_USER_STAMP; + private transient byte nextStamp = MINIMUM_USER_STAMP; /* Max value for stamp allowable before recalculation */ - private static int STAMP_MAX = 10000; + private static byte STAMP_MAX = Byte.MAX_VALUE; // the internal serial version which says which version was written // - 0 (default) for version up to JDK 1.1.5 @@ -1684,7 +1684,7 @@ private void setCalendarLocale(ULocale locale) { private void recalculateStamp() { int index; - int currentValue; + byte currentValue; int j, i; nextStamp = 1; @@ -1721,7 +1721,7 @@ private void initInternal() throw new IllegalStateException("Invalid fields[]"); } ///CLOVER:ON - stamp = new int[fields.length]; + stamp = new byte[fields.length]; int mask = (1 << ERA) | (1 << YEAR) | (1 << MONTH) | @@ -2057,6 +2057,7 @@ public void setTimeInMillis( long millis ) { for (int i=0; i