Backport 6633613: (str) StringCoding optimizations to avoid unnecessary array copies with Charset arg

Joe Darcy joe.darcy at oracle.com
Mon Aug 16 14:01:13 PDT 2010


Hi Martin.

Approved to be backported.

Thanks,

-Joe

Martin Buchholz wrote:
> Someone at Google ran into 6633613, and I thought it would be good to 
> backport this small safe fix to openjdk6.
>
> Martin
>
> # HG changeset patch
> # User martin
> # Date 1205125002 25200
> # Node ID 7fb2ca1b52c8f73a6f65bc51df55cd946b174ce7
> # Parent  b5da6145b050847df7aab8b5696b1d972a14c5ae
> 6633613: (str) StringCoding optimizations to avoid unnecessary array 
> copies with Charset arg
> Reviewed-by: iris
>
> diff --git a/src/share/classes/java/lang/StringCoding.java 
> b/src/share/classes/java/lang/StringCoding.java
> --- a/src/share/classes/java/lang/StringCoding.java
> +++ b/src/share/classes/java/lang/StringCoding.java
> @@ -194,8 +194,7 @@
>  
>      static char[] decode(Charset cs, byte[] ba, int off, int len) {
>          StringDecoder sd = new StringDecoder(cs, cs.name 
> <http://cs.name>());
> -        byte[] b = Arrays.copyOf(ba, ba.length);
> -        return sd.decode(b, off, len);
> +        return sd.decode(Arrays.copyOfRange(ba, off, off + len), 0, len);
>      }
>  
>      static char[] decode(byte[] ba, int off, int len) {
> @@ -293,8 +292,7 @@
>  
>      static byte[] encode(Charset cs, char[] ca, int off, int len) {
>          StringEncoder se = new StringEncoder(cs, cs.name 
> <http://cs.name>());
> -        char[] c = Arrays.copyOf(ca, ca.length);
> -        return se.encode(c, off, len);
> +        return se.encode(Arrays.copyOfRange(ca, off, off + len), 0, len);
>      }
>  
>      static byte[] encode(char[] ca, int off, int len) {
>



More information about the jdk6-dev mailing list