Commit 9d9bd40f by Tom Tromey Committed by Tom Tromey

Charset.java (encode, decode): Synchronize on 'this', not the class.

	* java/nio/charset/Charset.java (encode, decode): Synchronize on
	'this', not the class.

From-SVN: r99810
parent e5b58ee3
2005-05-16 Tom Tromey <tromey@redhat.com> 2005-05-16 Tom Tromey <tromey@redhat.com>
* java/nio/charset/Charset.java (encode, decode): Synchronize on
'this', not the class.
2005-05-16 Tom Tromey <tromey@redhat.com>
* gnu/java/net/protocol/http/Headers.java (parse): Include final * gnu/java/net/protocol/http/Headers.java (parse): Include final
character of line. character of line.
......
...@@ -289,25 +289,22 @@ public abstract class Charset implements Comparable ...@@ -289,25 +289,22 @@ public abstract class Charset implements Comparable
return true; 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 try
{ {
// NB: This implementation serializes different threads calling if (cachedEncoder == null)
// Charset.encode(), a potential performance problem. It might {
// be better to remove the cache, or use ThreadLocal to cache on cachedEncoder = newEncoder ()
// a per-thread basis. .onMalformedInput (CodingErrorAction.REPLACE)
synchronized (Charset.class) .onUnmappableCharacter (CodingErrorAction.REPLACE);
{ } else
if (cachedEncoder == null) cachedEncoder.reset();
{ return cachedEncoder.encode (cb);
cachedEncoder = newEncoder ()
.onMalformedInput (CodingErrorAction.REPLACE)
.onUnmappableCharacter (CodingErrorAction.REPLACE);
} else
cachedEncoder.reset();
return cachedEncoder.encode (cb);
}
} }
catch (CharacterCodingException e) catch (CharacterCodingException e)
{ {
...@@ -320,26 +317,23 @@ public abstract class Charset implements Comparable ...@@ -320,26 +317,23 @@ public abstract class Charset implements Comparable
return encode (CharBuffer.wrap (str)); 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 try
{ {
// NB: This implementation serializes different threads calling if (cachedDecoder == null)
// Charset.decode(), a potential performance problem. It might {
// be better to remove the cache, or use ThreadLocal to cache on cachedDecoder = newDecoder ()
// a per-thread basis. .onMalformedInput (CodingErrorAction.REPLACE)
synchronized (Charset.class) .onUnmappableCharacter (CodingErrorAction.REPLACE);
{ } else
if (cachedDecoder == null) cachedDecoder.reset();
{
cachedDecoder = newDecoder ()
.onMalformedInput (CodingErrorAction.REPLACE)
.onUnmappableCharacter (CodingErrorAction.REPLACE);
} else
cachedDecoder.reset();
return cachedDecoder.decode (bb); return cachedDecoder.decode (bb);
}
} }
catch (CharacterCodingException e) catch (CharacterCodingException e)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment