]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
de-pessimization
authorAnthony Green <green@redhat.com>
Wed, 25 Feb 2004 19:52:58 +0000 (19:52 +0000)
committerAnthony Green <green@gcc.gnu.org>
Wed, 25 Feb 2004 19:52:58 +0000 (19:52 +0000)
From-SVN: r78447

libjava/ChangeLog
libjava/java/lang/StringBuffer.java

index 6899b9200ce339eff9e2e475622405984bf64b1c..d5f171d147b463d593572ac62a3999a38a6dbc1f 100644 (file)
@@ -1,3 +1,9 @@
+2004-02-24  Anthony Green  <green@redhat.com>
+
+       * java/lang/StringBuffer.java: No need to NULL out remainder of
+       buffer since ensureCapacity_unsynchronized will have done this for
+       us.
+
 2004-02-20  Michael Koch  <konqueror@gmx.de>
 
        * gnu/java/net/protocol/jar/Handler.java
index 92f961534a13bab006517d1c6859e0b692bcd167..293b97d076ee560f8b244512355011c1d4c62a2a 100644 (file)
@@ -1,5 +1,6 @@
 /* StringBuffer.java -- Growable strings
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -205,10 +206,26 @@ public final class StringBuffer implements Serializable, CharSequence
     if (newLength < 0)
       throw new StringIndexOutOfBoundsException(newLength);
 
+    int valueLength = value.length;
+
+    /* Always call ensureCapacity_unsynchronized in order to preserve
+       copy-on-write semantics.  */
     ensureCapacity_unsynchronized(newLength);
-    while (count < newLength)
-      value[count++] = '\0';
-    count = newLength;
+
+    if (newLength < valueLength)
+      {
+        /* If the StringBuffer's value just grew, then we know that
+           value is newly allocated and the region between count and
+           newLength is filled with '\0'.  */
+       count = newLength;
+      }
+    else
+      {
+       /* The StringBuffer's value doesn't need to grow.  However,
+          we should clear out any cruft that may exist.  */
+       while (count < newLength)
+          value[count++] = '\0';
+      }
   }
 
   /**