diff options
author | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-25 19:52:58 +0000 |
---|---|---|
committer | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-02-25 19:52:58 +0000 |
commit | ab9b8800aa18a76d9514ccaeada3727e6d4a8a9c (patch) | |
tree | 03f26a2528069bc59ece0611b1e7167fc4700f47 /libjava | |
parent | cacee710b3bbe9d010c6dce2e7ede23a1329941a (diff) | |
download | gcc-ab9b8800aa18a76d9514ccaeada3727e6d4a8a9c.tar.gz |
de-pessimization
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@78447 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 6 | ||||
-rw-r--r-- | libjava/java/lang/StringBuffer.java | 25 |
2 files changed, 27 insertions, 4 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 6899b9200ce..d5f171d147b 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -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 diff --git a/libjava/java/lang/StringBuffer.java b/libjava/java/lang/StringBuffer.java index 92f961534a1..293b97d076e 100644 --- a/libjava/java/lang/StringBuffer.java +++ b/libjava/java/lang/StringBuffer.java @@ -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'; + } } /** |