classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: FYI: Charset fixlet


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: Charset fixlet
Date: 16 May 2005 19:48:48 -0600
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in on the trunk and to Classpath.
4.0 is a bit different here, so this patch won't work there.

Charset keeps a couple of caches.  This patch changes it to
synchronize on 'this' instead of on the Class when manipulating the
cache.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>
        * java/nio/charset/Charset.java (encode, decode): Synchronize on
        'this', not the class.

Index: java/nio/charset/Charset.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/charset/Charset.java,v
retrieving revision 1.11
diff -u -r1.11 Charset.java
--- java/nio/charset/Charset.java 29 Apr 2005 06:54:47 -0000 1.11
+++ java/nio/charset/Charset.java 17 May 2005 01:50:11 -0000
@@ -289,25 +289,22 @@
     return true;
   }
 
-  public final ByteBuffer encode (CharBuffer cb)
+  // NB: This implementation serializes different threads calling
+  // Charset.encode(), a potential performance problem.  It might
+  // be better to remove the cache, or use ThreadLocal to cache on
+  // a per-thread basis.
+  public final synchronized ByteBuffer encode (CharBuffer cb)
   {
     try
       {
-        // NB: This implementation serializes different threads calling
-        // Charset.encode(), a potential performance problem.  It might
-        // be better to remove the cache, or use ThreadLocal to cache on
-        // a per-thread basis.
-        synchronized (Charset.class)
-          {
-            if (cachedEncoder == null)
-              {
-                cachedEncoder = newEncoder ()
-                  .onMalformedInput (CodingErrorAction.REPLACE)
-                  .onUnmappableCharacter (CodingErrorAction.REPLACE);
-              } else
-               cachedEncoder.reset();
-            return cachedEncoder.encode (cb);
-          }
+       if (cachedEncoder == null)
+         {
+           cachedEncoder = newEncoder ()
+             .onMalformedInput (CodingErrorAction.REPLACE)
+             .onUnmappableCharacter (CodingErrorAction.REPLACE);
+         } else
+         cachedEncoder.reset();
+       return cachedEncoder.encode (cb);
       }
     catch (CharacterCodingException e)
       {
@@ -320,26 +317,23 @@
     return encode (CharBuffer.wrap (str));
   }
 
-  public final CharBuffer decode (ByteBuffer bb)
+  // NB: This implementation serializes different threads calling
+  // Charset.decode(), a potential performance problem.  It might
+  // be better to remove the cache, or use ThreadLocal to cache on
+  // a per-thread basis.
+  public final synchronized CharBuffer decode (ByteBuffer bb)
   {
     try
       {
-        // NB: This implementation serializes different threads calling
-        // Charset.decode(), a potential performance problem.  It might
-        // be better to remove the cache, or use ThreadLocal to cache on
-        // a per-thread basis.
-        synchronized (Charset.class)
-          {
-            if (cachedDecoder == null)
-              {
-                cachedDecoder = newDecoder ()
-                  .onMalformedInput (CodingErrorAction.REPLACE)
-                  .onUnmappableCharacter (CodingErrorAction.REPLACE);
-              } else
-               cachedDecoder.reset();
+       if (cachedDecoder == null)
+         {
+           cachedDecoder = newDecoder ()
+             .onMalformedInput (CodingErrorAction.REPLACE)
+             .onUnmappableCharacter (CodingErrorAction.REPLACE);
+         } else
+         cachedDecoder.reset();
 
-            return cachedDecoder.decode (bb);
-          }
+       return cachedDecoder.decode (bb);
       }
     catch (CharacterCodingException e)
       {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]