summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-15 17:02:16 -0700
committerElliott Hughes <enh@google.com>2009-09-15 17:02:16 -0700
commiteb6b2b61f6ae5f42fa3d147e30a953296ebdf870 (patch)
tree77b84167ebc4ae1211f98c8ae33e9f3ef9f897be /icu/src/main/java
parent2564a911708acb90dfb9ecbff93ac560da01117a (diff)
downloadlibcore-eb6b2b61f6ae5f42fa3d147e30a953296ebdf870.zip
libcore-eb6b2b61f6ae5f42fa3d147e30a953296ebdf870.tar.gz
libcore-eb6b2b61f6ae5f42fa3d147e30a953296ebdf870.tar.bz2
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.
Diffstat (limited to 'icu/src/main/java')
-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);