summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-03-05 17:09:59 -0800
committerElliott Hughes <enh@google.com>2010-03-05 17:09:59 -0800
commit37911714582b8d92ad7d814d6f810195452a67ab (patch)
tree473a435a7922c63f46cf404a6bfdede85d6cb0b8 /icu/src/main/java
parent323ad1674a32e01e6dc480564e3d942212b06458 (diff)
downloadlibcore-37911714582b8d92ad7d814d6f810195452a67ab.zip
libcore-37911714582b8d92ad7d814d6f810195452a67ab.tar.gz
libcore-37911714582b8d92ad7d814d6f810195452a67ab.tar.bz2
Use a manually-synchronized HashMap instead of ConcurrentHashMap in LocaleData.
ConcurrentHashMap is our slowest choice at the moment: ConcurrentHashMapGet 782 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HashMapGet 272 XXXXXXXXXX||||||||||||||| HashMapGet_Synchronized 317 XXXXXXXXXXXX||||||||||||| HashtableGet 325 XXXXXXXXXXXX|||||||||||||| LinkedHashMapGet 280 XXXXXXXXXX||||||||||||||| The cost of some commonly-created temporary objects (such as DateFormatSymbols) is dominated by the lookup of the locale data. This patch takes "new DateFormatSymbols" from 3us to 2.3us on passion/froyo (a 23% drop). Bug: 2492505
Diffstat (limited to 'icu/src/main/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/util/Resources.java26
1 files changed, 17 insertions, 9 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 53be6ab..4a91d62 100644
--- a/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
+++ b/icu/src/main/java/com/ibm/icu4jni/util/Resources.java
@@ -18,12 +18,12 @@ package com.ibm.icu4jni.util;
import java.util.Arrays;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.ListResourceBundle;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.TimeZone;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
/**
@@ -33,8 +33,8 @@ import java.util.logging.Logger;
*/
public class Resources {
// A cache for the locale-specific data.
- private static final ConcurrentHashMap<String, LocaleData> localeDataCache =
- new ConcurrentHashMap<String, LocaleData>();
+ private static final HashMap<String, LocaleData> localeDataCache =
+ new HashMap<String, LocaleData>();
/**
* Cache for ISO language names.
@@ -64,13 +64,21 @@ public class Resources {
locale = Locale.getDefault();
}
String localeName = locale.toString();
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ }
+ LocaleData newLocaleData = makeLocaleData(locale);
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ localeDataCache.put(localeName, newLocaleData);
+ return newLocaleData;
}
- localeData = makeLocaleData(locale);
- boolean absent = (localeDataCache.putIfAbsent(localeName, localeData) == null);
- return absent ? localeData : localeDataCache.get(localeName);
}
private static LocaleData makeLocaleData(Locale locale) {