From b31ce36a7d60a398ab92a9f18746d14a3e0ef2e1 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 30 Dec 2024 20:33:10 -0800 Subject: [PATCH 1/5] 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 Date: Fri, 3 Jan 2025 15:50:12 -0800 Subject: [PATCH 2/5] Update icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java Co-authored-by: Markus Scherer --- icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java index 85b3a9c32ee9..0235ea231770 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java @@ -2054,9 +2054,8 @@ public void setTimeInMillis( long millis ) { areFieldsSet = areAllFieldsSet = false; isTimeSet = areFieldsVirtuallySet = true; - for (int i=0; i Date: Fri, 3 Jan 2025 15:50:19 -0800 Subject: [PATCH 3/5] Update icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java Co-authored-by: Markus Scherer --- icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java index 0235ea231770..feb9e8e89b1e 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java @@ -2455,9 +2455,8 @@ public final void setRelatedYear(int year) { */ public final void clear() { - for (int i=0; i Date: Fri, 3 Jan 2025 15:50:29 -0800 Subject: [PATCH 4/5] Update icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java Co-authored-by: Markus Scherer --- icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java index feb9e8e89b1e..a886eed1bd2e 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/Calendar.java @@ -1355,7 +1355,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable Date: Fri, 3 Jan 2025 15:50:43 -0800 Subject: [PATCH 5/5] Update icu4c/source/i18n/unicode/calendar.h Co-authored-by: Markus Scherer --- icu4c/source/i18n/unicode/calendar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h index 9be0a2bb8dc5..8a07c37b8925 100644 --- a/icu4c/source/i18n/unicode/calendar.h +++ b/icu4c/source/i18n/unicode/calendar.h @@ -1951,7 +1951,7 @@ class U_I18N_API Calendar : public UObject { /** * Pseudo-time-stamps which specify when each field was set. There * are two special values, UNSET and INTERNALLY_SET. Values from - * MINIMUM_USER_SET to 127 are legal user set values. + * MINIMUM_USER_SET to STAMP_MAX are legal user set values. */ int8_t fStamp[UCAL_FIELD_COUNT];