jdk/src/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java
changeset 15260 7af2d7a87806
parent 14502 d63fed06fed4
child 16052 60d3d3dd4880
--- a/jdk/src/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java	Sun Jan 13 19:57:06 2013 -0500
+++ b/jdk/src/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java	Mon Jan 14 11:09:53 2013 -0800
@@ -37,6 +37,8 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.spi.CalendarDataProvider;
 import java.util.spi.CalendarNameProvider;
 import java.util.spi.CurrencyNameProvider;
@@ -44,7 +46,6 @@
 import java.util.spi.LocaleServiceProvider;
 import java.util.spi.TimeZoneNameProvider;
 import sun.util.cldr.CLDRLocaleProviderAdapter;
-import sun.util.resources.LocaleData;
 
 /**
  * The LocaleProviderAdapter abstract class.
@@ -119,6 +120,12 @@
      */
     private static LocaleProviderAdapter fallbackLocaleProviderAdapter = null;
 
+    /**
+     * Adapter lookup cache.
+     */
+    private static ConcurrentMap<Class<? extends LocaleServiceProvider>, ConcurrentMap<Locale, LocaleProviderAdapter>>
+        adapterCache = new ConcurrentHashMap<>();
+
     static {
         String order = AccessController.doPrivileged(
                            new sun.security.action.GetPropertyAction("java.locale.providers"));
@@ -210,9 +217,23 @@
      */
     public static LocaleProviderAdapter getAdapter(Class<? extends LocaleServiceProvider> providerClass,
                                                Locale locale) {
+        LocaleProviderAdapter adapter;
+
+        // cache lookup
+        ConcurrentMap<Locale, LocaleProviderAdapter> adapterMap = adapterCache.get(providerClass);
+        if (adapterMap != null) {
+            if ((adapter = adapterMap.get(locale)) != null) {
+                return adapter;
+            }
+        } else {
+            adapterMap = new ConcurrentHashMap<>();
+            adapterCache.putIfAbsent(providerClass, adapterMap);
+        }
+
         // Fast look-up for the given locale
-        LocaleProviderAdapter adapter = findAdapter(providerClass, locale);
+        adapter = findAdapter(providerClass, locale);
         if (adapter != null) {
+            adapterMap.putIfAbsent(locale, adapter);
             return adapter;
         }
 
@@ -226,11 +247,13 @@
             }
             adapter = findAdapter(providerClass, loc);
             if (adapter != null) {
+                adapterMap.putIfAbsent(locale, adapter);
                 return adapter;
             }
         }
 
         // returns the adapter for FALLBACK as the last resort
+        adapterMap.putIfAbsent(locale, fallbackLocaleProviderAdapter);
         return fallbackLocaleProviderAdapter;
     }
 
@@ -398,7 +421,5 @@
 
     public abstract LocaleResources getLocaleResources(Locale locale);
 
-    public abstract LocaleData getLocaleData();
-
     public abstract Locale[] getAvailableLocales();
 }