diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-05-17 01:52:02 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-05-17 01:52:02 +0000 |
commit | 7558cc602bbbf6a457d8163cb10692a1a9ad5b0c (patch) | |
tree | 9e725d3de52f3724939de6899c9e60f4d9a069aa /libjava/java/nio | |
parent | f63a3d185221a9f55cf33bbf69e4fe9c9a990e80 (diff) | |
download | gcc-7558cc602bbbf6a457d8163cb10692a1a9ad5b0c.tar.gz |
* java/nio/charset/Charset.java (encode, decode): Synchronize on
'this', not the class.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@99810 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/nio')
-rw-r--r-- | libjava/java/nio/charset/Charset.java | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/libjava/java/nio/charset/Charset.java b/libjava/java/nio/charset/Charset.java index d52fc9c7d21..8c6286db9ca 100644 --- a/libjava/java/nio/charset/Charset.java +++ b/libjava/java/nio/charset/Charset.java @@ -289,25 +289,22 @@ public abstract class Charset implements Comparable 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 @@ public abstract class Charset implements Comparable 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) { |