changeset 415:78235ae077a1

6633613: (str) StringCoding optimizations to avoid unnecessary array copies with Charset arg Reviewed-by: iris
author martin
date Sun, 09 Mar 2008 21:56:42 -0700
parents ac23e40d3880
children 13ad7a024dfc
files src/share/classes/java/lang/StringCoding.java
diffstat 1 files changed, 2 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/StringCoding.java	Fri Aug 13 10:36:08 2010 -0400
+++ b/src/share/classes/java/lang/StringCoding.java	Sun Mar 09 21:56:42 2008 -0700
@@ -193,8 +193,7 @@
 
     static char[] decode(Charset cs, byte[] ba, int off, int len) {
         StringDecoder sd = new StringDecoder(cs, 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) {
@@ -292,8 +291,7 @@
 
     static byte[] encode(Charset cs, char[] ca, int off, int len) {
         StringEncoder se = new StringEncoder(cs, 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) {