Tom Tromey wrote:
"Ian" == Ian Rogers <[EMAIL PROTECTED]> writes:

Ian> Please let me know if you think this patch is suitable for
Ian> inclusion.

It looks fine.  I do have one nit, which is that we put spaces around
operators... this problem is pervasive in the patch, but here's one
example:

Ian> +    newStr[x-offset] = newChar;

That should read

    newStr[x - offset] = newChar;

Tom
Thanks Tom,

here is a revised patch that if there are no other problems I'd like to commit today.

Regards,
Ian
Index: ChangeLog
===================================================================
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.9481
diff -u -r1.9481 ChangeLog
--- ChangeLog   6 Feb 2008 19:00:44 -0000       1.9481
+++ ChangeLog   7 Feb 2008 09:21:01 -0000
@@ -1,3 +1,8 @@
+2008-02-07  Ian Rogers  <[EMAIL PROTECTED]>
+
+       * java/lang/String.java
+       Only copy "live" portion of String. Use array copies in preference to 
clone.
+
 2008-02-05  Ian Rogers  <[EMAIL PROTECTED]>
 
        * gnu/java/lang/reflect/TypeSignature.java
Index: java/lang/String.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/String.java,v
retrieving revision 1.87
diff -u -r1.87 String.java
--- java/lang/String.java       23 Nov 2007 15:04:25 -0000      1.87
+++ java/lang/String.java       7 Feb 2008 09:21:01 -0000
@@ -1303,13 +1303,13 @@
         break;
     if (i < 0)
       return this;
-    char[] newStr = (char[]) value.clone();
-    newStr[x] = newChar;
+    char[] newStr = toCharArray();
+    newStr[x - offset] = newChar;
     while (--i >= 0)
       if (value[++x] == oldChar)
-        newStr[x] = newChar;
+        newStr[x - offset] = newChar;
     // Package constructor avoids an array copy.
-    return new String(newStr, offset, count, true);
+    return new String(newStr, 0, count, true);
   }
 
   /**
@@ -1450,23 +1450,25 @@
 
     // Now we perform the conversion. Fortunately, there are no multi-character
     // lowercase expansions in Unicode 3.0.0.
-    char[] newStr = (char[]) value.clone();
+    char[] newStr = new char[count];
+    VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
     do
       {
         char ch = value[x];
         // Hardcoded special case.
         if (ch != '\u0049')
           {
-            newStr[x++] = Character.toLowerCase(ch);
+            newStr[x - offset] = Character.toLowerCase(ch);
           }
         else
           {
-            newStr[x++] = '\u0131';
+            newStr[x - offset] = '\u0131';
           }
+        x++;
       }
     while (--i >= 0);
     // Package constructor avoids an array copy.
-    return new String(newStr, offset, count, true);
+    return new String(newStr, 0, count, true);
   }
 
   /**
@@ -1504,16 +1506,18 @@
 
         // Now we perform the conversion. Fortunately, there are no
         // multi-character lowercase expansions in Unicode 3.0.0.
-        char[] newStr = (char[]) value.clone();
+        char[] newStr = new char[count];
+        VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
         do
           {
             char ch = value[x];
             // Hardcoded special case.
-            newStr[x++] = Character.toLowerCase(ch);
+            newStr[x - offset] = Character.toLowerCase(ch);
+            x++;
           }
         while (--i >= 0);
         // Package constructor avoids an array copy.
-        return new String(newStr, offset, count, true);
+        return new String(newStr, 0, count, true);
      }
   }
 
@@ -1557,22 +1561,24 @@
     i = count;
     if (expand == 0)
       {
-        char[] newStr = (char[]) value.clone();
+        char[] newStr = new char[count];
+        VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
         while (--i >= 0)
           {
             char ch = value[x];
             // Hardcoded special case.
             if (ch != '\u0069')
               {
-                newStr[x++] = Character.toUpperCase(ch);
+                newStr[x - offset] = Character.toUpperCase(ch);
               }
             else
               {
-                newStr[x++] = '\u0130';
+                newStr[x - offset] = '\u0130';
               }
+            x++;
           }
         // Package constructor avoids an array copy.
-        return new String(newStr, offset, count, true);
+        return new String(newStr, 0, count, true);
       }
 
     // Expansion is necessary.
@@ -1642,14 +1648,16 @@
         i = count;
         if (expand == 0)
           {
-            char[] newStr = (char[]) value.clone();
+            char[] newStr = new char[count];
+            VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
             while (--i >= 0)
               {
                 char ch = value[x];
-                newStr[x++] = Character.toUpperCase(ch);
+                newStr[x - offset] = Character.toUpperCase(ch);
+                x++;
               }
             // Package constructor avoids an array copy.
-            return new String(newStr, offset, count, true);
+            return new String(newStr, 0, count, true);
           }
 
         // Expansion is necessary.
@@ -1730,9 +1738,6 @@
    */
   public char[] toCharArray()
   {
-    if (count == value.length)
-      return (char[]) value.clone();
-
     char[] copy = new char[count];
     VMSystem.arraycopy(value, offset, copy, 0, count);
     return copy;

Reply via email to