harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r536876 - /harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/Charset.java
Date Thu, 10 May 2007 14:48:10 GMT
Author: apetrenko
Date: Thu May 10 07:48:09 2007
New Revision: 536876

URL: http://svn.apache.org/viewvc?view=rev&rev=536876
Log:
Patch for HARMONY-3493 "[classlib][nio]java.nio.Charset.encode()/decode() performance improvement."

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?view=diff&rev=536876&r1=536875&r2=536876
==============================================================================
--- 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
Thu May 10 07:48:09 2007
@@ -133,6 +133,8 @@
     // cached CharsetEncoder table
     private static HashMap<String, CharsetEncoder> cachedCharsetEncoderTable = new
HashMap<String, CharsetEncoder>();
 
+    private CharsetEncoder cachedEncoder = null;
+    private CharsetDecoder cachedDecoder = null; 
     /*
      * -------------------------------------------------------------------
      * Global initialization
@@ -672,10 +674,13 @@
      * @return the result of the encoding
      */
     synchronized public final ByteBuffer encode(CharBuffer buffer) {
-        CharsetEncoder e = getCachedCharsetEncoder(canonicalName);
+        if (cachedEncoder == null) {
+            cachedEncoder = getCachedCharsetEncoder(canonicalName);
+        }
+        
         try {
-            synchronized (e) {
-                return e.encode(buffer);
+            synchronized (cachedEncoder) {
+                return cachedEncoder.encode(buffer);
             }
         } catch (CharacterCodingException ex) {
             throw new Error(ex.getMessage(), ex);
@@ -727,10 +732,13 @@
      * @return a character buffer containing the output of the decoding
      */
     public final CharBuffer decode(ByteBuffer buffer) {
-        CharsetDecoder d = getCachedCharsetDecoder(canonicalName);
+        if (cachedDecoder == null) {
+            cachedDecoder = getCachedCharsetDecoder(canonicalName);
+        }
+
         try {
-            synchronized (d) {
-                return d.decode(buffer);
+            synchronized (cachedDecoder) {
+                return cachedDecoder.decode(buffer);
             }
         } catch (CharacterCodingException ex) {
             throw new Error(ex.getMessage(), ex);



Mime
View raw message