This patch makes the default capacity of CPStringBuilder configurable using the gnu.classpath.cpstringbuilder.capacity property. The default is 32, double that for StringBuilder/Buffer. If you this new default causes problems, or you find a better default, please let us know.
ChangeLog: 2008-05-11 Andrew John Hughes <[EMAIL PROTECTED]> * gnu/java/lang/CPStringBuilder.java: Make default capacity configurable. -- Andrew :) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: gnu/java/lang/CPStringBuilder.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/lang/CPStringBuilder.java,v retrieving revision 1.6 diff -u -r1.6 CPStringBuilder.java --- gnu/java/lang/CPStringBuilder.java 5 May 2008 22:21:15 -0000 1.6 +++ gnu/java/lang/CPStringBuilder.java 11 May 2008 15:38:25 -0000 @@ -38,6 +38,8 @@ package gnu.java.lang; +import gnu.classpath.SystemProperties; + import java.io.Serializable; /** @@ -58,7 +60,7 @@ * * @serial the number of characters in the buffer */ - int count; + private int count; /** * The buffer. Note that this has permissions set this way so that String @@ -66,15 +68,26 @@ * * @serial the buffer */ - char[] value; + private char[] value; /** * The default capacity of a buffer. + * This can be configured using gnu.classpath.cpstringbuilder.capacity */ - private static final int DEFAULT_CAPACITY = 16; + private static final int DEFAULT_CAPACITY; + + static + { + String cap = + SystemProperties.getProperty("gnu.classpath.cpstringbuilder.capacity"); + if (cap == null) + DEFAULT_CAPACITY = 32; + else + DEFAULT_CAPACITY = Integer.parseInt(cap); + } /** - * Create a new CPStringBuilder with default capacity 16. + * Create a new CPStringBuilder with the default capacity. */ public CPStringBuilder() { @@ -96,7 +109,7 @@ /** * Create a new <code>CPStringBuilder</code> with the characters in the * specified <code>String</code>. Initial capacity will be the size of the - * String plus 16. + * String plus the default capacity. * * @param str the <code>String</code> to convert * @throws NullPointerException if str is null @@ -111,7 +124,7 @@ /** * Create a new <code>CPStringBuilder</code> with the characters in the * specified <code>StringBuffer</code>. Initial capacity will be the size of the - * String plus 16. + * String plus the default capacity. * * @param str the <code>String</code> to convert * @throws NullPointerException if str is null @@ -126,7 +139,7 @@ /** * Create a new <code>CPStringBuilder</code> with the characters in the * specified <code>StringBuilder</code>. Initial capacity will be the size of the - * String plus 16. + * String plus the default capacity. * * @param str the <code>String</code> to convert * @throws NullPointerException if str is null @@ -141,8 +154,9 @@ /** * Create a new <code>CPStringBuilder</code> with the characters in the * specified <code>CharSequence</code>. Initial capacity will be the - * length of the sequence plus 16; if the sequence reports a length - * less than or equal to 0, then the initial capacity will be 16. + * length of the sequence plus the default capacity; if the sequence + * reports a length less than or equal to 0, then the initial capacity + * will be the default. * * @param seq the initializing <code>CharSequence</code> * @throws NullPointerException if str is null