diff options
Diffstat (limited to 'icu/src')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/util/Resources.java | 31 | ||||
-rw-r--r-- | icu/src/main/native/ResourceInterface.cpp | 19 |
2 files changed, 36 insertions, 14 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java index f1c50e3..cbad9a5 100644 --- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java +++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java @@ -29,7 +29,7 @@ import java.util.logging.Logger; /** * Makes ICU data accessible to Java. * - * TODO: finish removing the expensive ResourceBundle nonsense and rename this class. + * TODO: move the LocaleData stuff into LocaleData and rename this class. */ public class Resources { // A cache for the locale-specific data. @@ -152,13 +152,34 @@ public class Resources { * Returns the display name for the given time zone using the given locale. * * @param id The time zone ID, for example "Europe/Berlin" - * @param isDST Indicates whether daylight savings is in use + * @param daylight Indicates whether daylight savings is in use * @param style The style, 0 for long, 1 for short * @param locale The locale name, for example "en_US". * @return The desired display name */ - public static String getDisplayTimeZone(String id, boolean isDST, int style, String locale) { - return getDisplayTimeZoneNative(id, isDST, style, locale); + public static String getDisplayTimeZone(String id, boolean daylight, int style, String locale) { + // If we already have the strings, linear search through them is 10x quicker than + // calling ICU for just the one we want. + if (DefaultTimeZones.locale.equals(locale)) { + String result = lookupDisplayTimeZone(DefaultTimeZones.names, id, daylight, style); + if (result != null) { + return result; + } + } + return getDisplayTimeZoneNative(id, daylight, style, locale); + } + + public static String lookupDisplayTimeZone(String[][] zoneStrings, String id, boolean daylight, int style) { + for (String[] row : zoneStrings) { + if (row[0].equals(id)) { + if (daylight) { + return (style == TimeZone.LONG) ? row[3] : row[4]; + } else { + return (style == TimeZone.LONG) ? row[1] : row[2]; + } + } + } + return null; } /** @@ -238,7 +259,7 @@ public class Resources { * "Europe/Berlin". The other columns then hold for each row the * four time zone names with and without daylight savings and in * long and short format. It's exactly the array layout required by - * the TomeZone class. + * the TimeZone class. */ public static String[][] getDisplayTimeZones(String locale) { String defaultLocale = Locale.getDefault().toString(); diff --git a/icu/src/main/native/ResourceInterface.cpp b/icu/src/main/native/ResourceInterface.cpp index 151b23e..3cb4224 100644 --- a/icu/src/main/native/ResourceInterface.cpp +++ b/icu/src/main/native/ResourceInterface.cpp @@ -252,6 +252,12 @@ static TimeZone* timeZoneFromId(JNIEnv* env, jstring id) { return TimeZone::createTimeZone(zoneID); } +static jstring formatDate(JNIEnv* env, const SimpleDateFormat& fmt, const UDate& when) { + UnicodeString str; + fmt.format(when, str); + return env->NewString(str.getBuffer(), str.length()); +} + static void getTimeZonesNative(JNIEnv* env, jclass clazz, jobjectArray outerArray, jstring locale) { @@ -304,24 +310,19 @@ static void getTimeZonesNative(JNIEnv* env, jclass clazz, daylightSavingDate = date2; } - UnicodeString str; - shortFormat.format(daylightSavingDate, str); - jstring content = env->NewString(str.getBuffer(), str.length()); + jstring content = formatDate(env, shortFormat, daylightSavingDate); env->SetObjectArrayElement(shortDlTimeArray, i, content); env->DeleteLocalRef(content); - shortFormat.format(standardDate, str); - content = env->NewString(str.getBuffer(), str.length()); + content = formatDate(env, shortFormat, standardDate); env->SetObjectArrayElement(shortStdTimeArray, i, content); env->DeleteLocalRef(content); - longFormat.format(daylightSavingDate, str); - content = env->NewString(str.getBuffer(), str.length()); + content = formatDate(env, longFormat, daylightSavingDate); env->SetObjectArrayElement(longDlTimeArray, i, content); env->DeleteLocalRef(content); - longFormat.format(standardDate, str); - content = env->NewString(str.getBuffer(), str.length()); + content = formatDate(env, longFormat, standardDate); env->SetObjectArrayElement(longStdTimeArray, i, content); env->DeleteLocalRef(content); |