From eb6b2b61f6ae5f42fa3d147e30a953296ebdf870 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 15 Sep 2009 17:02:16 -0700 Subject: Make Resources$DefaultTimeZones preloadable again. http://s9/81864 was a premature optimization that stopped the timezone data being loaded in the zygote. So instead of paying the (admittedly large) time and space costs once in the zygote, we now pay them once per application. Revert the problematic parts of that change. Note that this isn't simply a reverse patch: 1. I've changed the comment to make it clear that although this *looks* like idiomatic lazy initialization, it's actually the opposite. A comment to that effect might have prevented this code from being broken. 2. I've left the last two hunks of the original patch stand, because they appear reasonable but unrelated. Bug: 1941311, 1819285. --- .../main/java/com/ibm/icu4jni/util/Resources.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'icu/src') 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 85530ac..0460fde 100644 --- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java +++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java @@ -179,20 +179,28 @@ public class Resources { private static String getDefaultLocaleName() { return java.util.Locale.getDefault().toString(); } - - /** - * Name of default locale at the time this class was initialized. - */ - private static final String initialLocale = getDefaultLocaleName(); /** - * Names of time zones for the default locale. + * Initialization holder for default time zone names. This class will + * be preloaded by the zygote to share the time and space costs of setting + * up the list of time zone names, so although it looks like the lazy + * initialization idiom, it's actually the opposite. */ - private static String[][] defaultTimezoneNames = null; + private static class DefaultTimeZones { + /** + * Name of default locale at the time this class was initialized. + */ + private static final String locale = getDefaultLocaleName(); + + /** + * Names of time zones for the default locale. + */ + private static final String[][] names = createTimeZoneNamesFor(locale); + } /** * Creates array of time zone names for the given locale. This method takes - * about 2s to run on a 400mhz ARM11. + * about 2s to run on a 400MHz ARM11. */ private static String[][] createTimeZoneNamesFor(String locale) { long start = System.currentTimeMillis(); @@ -252,22 +260,16 @@ public class Resources { * the TomeZone class. */ public static String[][] getDisplayTimeZones(String locale) { - // Note: Defer loading DefaultTimeZones as long as possible. - - String defaultLocaleName = getDefaultLocaleName(); + String defaultLocale = getDefaultLocaleName(); if (locale == null) { - locale = defaultLocaleName; + locale = defaultLocale; } // If locale == default and the default locale hasn't changed since // DefaultTimeZones loaded, return the cached names. // TODO: We should force a reboot if the default locale changes. - if (defaultLocaleName.equals(locale) - && initialLocale.equals(defaultLocaleName)) { - if (defaultTimezoneNames == null) { - defaultTimezoneNames = createTimeZoneNamesFor(locale); - } - return defaultTimezoneNames; + if (defaultLocale.equals(locale) && DefaultTimeZones.locale.equals(defaultLocale)) { + return DefaultTimeZones.names; } return createTimeZoneNamesFor(locale); -- cgit v1.1