summaryrefslogtreecommitdiffstats
path: root/icu/src
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-17 09:48:00 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2009-09-17 09:48:00 -0700
commit35a3f0960b74cf78fc4956e32935f8b1015fac65 (patch)
treed358cd93e4ba92ac2f6aaae636a03dbe116c52c2 /icu/src
parentcb546789aa4f0dfce316f131562f5c089ef13cce (diff)
parent01d4beba95fe8f72b79fce5c58fc6bfe39809d86 (diff)
downloadlibcore-35a3f0960b74cf78fc4956e32935f8b1015fac65.zip
libcore-35a3f0960b74cf78fc4956e32935f8b1015fac65.tar.gz
libcore-35a3f0960b74cf78fc4956e32935f8b1015fac65.tar.bz2
am d9f8adbf: am cb12fde6: Make Resources preloadable again.
Merge commit 'd9f8adbfa912c24fb29d2a7e2ce7421a3f96ef82' * commit 'd9f8adbfa912c24fb29d2a7e2ce7421a3f96ef82': Make Resources$DefaultTimeZones preloadable again.
Diffstat (limited to 'icu/src')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/Resources.java38
1 files changed, 20 insertions, 18 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 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);