harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r698500 - /harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java
Date Wed, 24 Sep 2008 10:06:20 GMT
Author: tellison
Date: Wed Sep 24 03:06:20 2008
New Revision: 698500

URL: http://svn.apache.org/viewvc?rev=698500&view=rev
Log:
Apply patch for HARMONY-5695 ([classlib][nio_char] speed up of Charset.forNameInternal)

Modified:
    harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java

Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java?rev=698500&r1=698499&r2=698500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java
Wed Sep 24 03:06:20 2008
@@ -106,7 +106,7 @@
     private final HashSet<String> aliasesSet;
 
     // cached Charset table
-    private static HashMap<String, Charset> cachedCharsetTable = new HashMap<String,
Charset>();
+    private final static HashMap<String, Charset> cachedCharsetTable = new HashMap<String,
Charset>();
 
     static {
         /*
@@ -423,56 +423,54 @@
     }
 
     /*
-     * Gets a <code> Charset </code> instance for the specified charset name.
If
+     * Gets a <code>Charset</code> instance for the specified charset name. If
      * the charset is not supported, returns null instead of throwing an
      * exception.
      */
-    private static Charset forNameInternal(String charsetName)
+    private synchronized static Charset forNameInternal(String charsetName)
             throws IllegalCharsetNameException {
+        Charset cs = cachedCharsetTable.get(charsetName);
+        if (null != cs) {
+            return cs;
+        }
+
         if (null == charsetName) {
             throw new IllegalArgumentException();
         }
         checkCharsetName(charsetName);
-        synchronized (Charset.class) {
-            // Try to get Charset from cachedCharsetTable
-            Charset cs = getCachedCharset(charsetName);
-            if (null != cs) {
-                return cs;
-            }
-            // Try built-in charsets
-            if (_builtInProvider == null) {
-                _builtInProvider = new CharsetProviderImpl();
-            }
-            cs = _builtInProvider.charsetForName(charsetName);
-            if (null != cs) {
-                cacheCharset(cs);
-                return cs;
-            }
-
-            // Collect all charsets provided by charset providers
-            ClassLoader contextClassLoader = getContextClassLoader();
-            Enumeration<URL> e = null;
-            try {
-                if (null != contextClassLoader) {
-                    e = contextClassLoader
-                            .getResources(PROVIDER_CONFIGURATION_FILE_NAME);
-                } else {
-                    getSystemClassLoader();
-                    e = systemClassLoader
-                            .getResources(PROVIDER_CONFIGURATION_FILE_NAME);
-                }
-                // Examine each configuration file
-                while (e.hasMoreElements()) {
-                    cs = searchConfiguredCharsets(charsetName,
-                            contextClassLoader, e.nextElement());
-                    if (null != cs) {
-                        cacheCharset(cs);
-                        return cs;
-                    }
+        // try built-in charsets
+        if (_builtInProvider == null) {
+            _builtInProvider = new CharsetProviderImpl();
+        }
+        cs = _builtInProvider.charsetForName(charsetName);
+        if (null != cs) {
+            cacheCharset(cs);
+            return cs;
+        }
+
+        // collect all charsets provided by charset providers
+        ClassLoader contextClassLoader = getContextClassLoader();
+        Enumeration<URL> e = null;
+        try {
+            if (null != contextClassLoader) {
+                e = contextClassLoader
+                        .getResources(PROVIDER_CONFIGURATION_FILE_NAME);
+            } else {
+                getSystemClassLoader();
+                e = systemClassLoader
+                        .getResources(PROVIDER_CONFIGURATION_FILE_NAME);
+            }
+            // examine each configuration file
+            while (e.hasMoreElements()) {
+                cs = searchConfiguredCharsets(charsetName, contextClassLoader,
+                        e.nextElement());
+                if (null != cs) {
+                    cacheCharset(cs);
+                    return cs;
                 }
-            } catch (IOException ex) {
-                // Unexpected ClassLoader exception, ignore
             }
+        } catch (IOException ex) {
+            // Unexpected ClassLoader exception, ignore
         }
         return null;
     }
@@ -492,13 +490,6 @@
         }
     }
 
-    /*
-     * get cached charset reference by name
-     */
-    private static Charset getCachedCharset(String name) {
-        return cachedCharsetTable.get(name);
-    }
-
     /**
      * Gets a <code>Charset</code> instance for the specified charset name.
      * 



Mime
View raw message