Hi John,

I think your change is correct. The loop can also be optimized a little if
we check beforehand for the completely whitespace case, so I'm checking in
the patch below.

I noticed you cc'd the libgcj patches list: this problem does not apply to
libgcj, because it has a different (native) implementation of String.

regards

  [ bryce ]

"[EMAIL PROTECTED]" wrote:

> I had problems with the String.trim() method, changing it from:

[...]

> Note I just added "+ 1" in the return line.
>
> I haven't tested this thoroughly but it made my problems go away.
2000-05-15  Bryce McKinlay  <[EMAIL PROTECTED]>

        * java/lang/String.java (trim): Optimize `end' loop. Don't lose the 
        last character of the returned string. 

===================================================================
RCS file: /cvs/classpath/java/lang/String.java,v
retrieving revision 1.27
diff -u -r1.27 String.java
--- String.java 2000/05/09 02:12:26     1.27
+++ String.java 2000/05/15 09:10:29
@@ -905,14 +905,18 @@
     if (count == 0 || (value[0] > '\u0020' && value[count-1] > '\u0020'))
       return this;
     int begin = 0;
-    for (; begin < count; begin++)
-      if (value[begin] > '\u0020')
-       break;
-    int end = count-1;
-    for (; end >= 0; end--)
-      if (value[end] > '\u0020')
-       break;
-    return substring(begin, end);
+    for (;; begin++)
+      {
+       if (begin == count)
+         return "";
+       if (value[begin] > '\u0020')
+         break;
+      }
+    int end = count;
+    for (;;)
+      if (value[--end] > '\u0020')
+        break;
+    return substring(begin, end + 1);
   }
 
   /**

Reply via email to