/[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.21 by mark, Fri Apr 29 14:34:44 2005 UTC revision 1.22 by tromey, Tue May 17 01:52:28 2005 UTC
# Line 329  public abstract class Charset implements Line 329  public abstract class Charset implements
329      return true;      return true;
330    }    }
331    
332    public final ByteBuffer encode (CharBuffer cb)    // NB: This implementation serializes different threads calling
333      // Charset.encode(), a potential performance problem.  It might
334      // be better to remove the cache, or use ThreadLocal to cache on
335      // a per-thread basis.
336      public final synchronized ByteBuffer encode (CharBuffer cb)
337    {    {
338      try      try
339        {        {
340          // NB: This implementation serializes different threads calling          if (cachedEncoder == null)
341          // Charset.encode(), a potential performance problem.  It might            {
342          // be better to remove the cache, or use ThreadLocal to cache on              cachedEncoder = newEncoder ()
343          // a per-thread basis.                .onMalformedInput (CodingErrorAction.REPLACE)
344          synchronized (Charset.class)                .onUnmappableCharacter (CodingErrorAction.REPLACE);
345            {            } else
346              if (cachedEncoder == null)            cachedEncoder.reset();
347                {          return cachedEncoder.encode (cb);
                 cachedEncoder = newEncoder ()  
                   .onMalformedInput (CodingErrorAction.REPLACE)  
                   .onUnmappableCharacter (CodingErrorAction.REPLACE);  
               } else  
                 cachedEncoder.reset();  
             return cachedEncoder.encode (cb);  
           }  
348        }        }
349      catch (CharacterCodingException e)      catch (CharacterCodingException e)
350        {        {
# Line 360  public abstract class Charset implements Line 357  public abstract class Charset implements
357      return encode (CharBuffer.wrap (str));      return encode (CharBuffer.wrap (str));
358    }    }
359    
360    public final CharBuffer decode (ByteBuffer bb)    // NB: This implementation serializes different threads calling
361      // Charset.decode(), a potential performance problem.  It might
362      // be better to remove the cache, or use ThreadLocal to cache on
363      // a per-thread basis.
364      public final synchronized CharBuffer decode (ByteBuffer bb)
365    {    {
366      try      try
367        {        {
368          // NB: This implementation serializes different threads calling          if (cachedDecoder == null)
369          // Charset.decode(), a potential performance problem.  It might            {
370          // be better to remove the cache, or use ThreadLocal to cache on              cachedDecoder = newDecoder ()
371          // a per-thread basis.                .onMalformedInput (CodingErrorAction.REPLACE)
372          synchronized (Charset.class)                .onUnmappableCharacter (CodingErrorAction.REPLACE);
373            {            } else
374              if (cachedDecoder == null)            cachedDecoder.reset();
               {  
                 cachedDecoder = newDecoder ()  
                   .onMalformedInput (CodingErrorAction.REPLACE)  
                   .onUnmappableCharacter (CodingErrorAction.REPLACE);  
               } else  
                 cachedDecoder.reset();  
375    
376              return cachedDecoder.decode (bb);          return cachedDecoder.decode (bb);
           }  
377        }        }
378      catch (CharacterCodingException e)      catch (CharacterCodingException e)
379        {        {

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

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