/[classpath]/classpath/java/nio/charset/Charset.java
ViewVC logotype

Diff of /classpath/java/nio/charset/Charset.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mkoch, Sat Nov 16 15:22:16 2002 UTC revision 1.9 by mkoch, Fri Nov 22 12:35:11 2002 UTC
# Line 57  public abstract class Charset implements Line 57  public abstract class Charset implements
57  {  {
58    private static CharsetEncoder cachedEncoder;    private static CharsetEncoder cachedEncoder;
59    private static CharsetDecoder cachedDecoder;    private static CharsetDecoder cachedDecoder;
60      
61      static
62      {
63        synchronized (Charset.class)
64          {
65            cachedEncoder = null;
66            cachedDecoder = null;
67          }
68      }
69    
70    private final String canonicalName;    private final String canonicalName;
71    private final String[] aliases;    private final String[] aliases;
72        
# Line 198  public abstract class Charset implements Line 207  public abstract class Charset implements
207    {    {
208      try      try
209        {        {
210          if (cachedEncoder == null)          // NB: This implementation serializes different threads calling
211            // Charset.encode(), a potential performance problem.  It might
212            // be better to remove the cache, or use ThreadLocal to cache on
213            // a per-thread basis.
214            synchronized (Charset.class)
215            {            {
216              cachedEncoder = newEncoder ()              if (cachedEncoder == null)
217                .onMalformedInput (CodingErrorAction.REPLACE)                {
218                .onUnmappableCharacter (CodingErrorAction.REPLACE);                  cachedEncoder = newEncoder ()
219            }                    .onMalformedInput (CodingErrorAction.REPLACE)
220                                        .onUnmappableCharacter (CodingErrorAction.REPLACE);
221          return cachedEncoder.encode (cb);                }
222    
223                return cachedEncoder.encode (cb);
224              }
225        }        }
226      catch (CharacterCodingException e)      catch (CharacterCodingException e)
227        {        {
# Line 221  public abstract class Charset implements Line 237  public abstract class Charset implements
237    public CharBuffer decode (ByteBuffer bb)    public CharBuffer decode (ByteBuffer bb)
238    {    {
239      try      try
240       {        {
241          if (cachedDecoder == null)          // NB: This implementation serializes different threads calling
242            // Charset.decode(), a potential performance problem.  It might
243            // be better to remove the cache, or use ThreadLocal to cache on
244            // a per-thread basis.
245            synchronized (Charset.class)
246            {            {
247              cachedDecoder = newDecoder ()              if (cachedDecoder == null)
248                .onMalformedInput (CodingErrorAction.REPLACE)                {
249                .onUnmappableCharacter (CodingErrorAction.REPLACE);                  cachedDecoder = newDecoder ()
250            }                    .onMalformedInput (CodingErrorAction.REPLACE)
251                              .onUnmappableCharacter (CodingErrorAction.REPLACE);
252          return cachedDecoder.decode (bb);                }
253    
254                return cachedDecoder.decode (bb);
255              }
256        }        }
257      catch (CharacterCodingException e)      catch (CharacterCodingException e)
258        {        {

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26