Hi,

the attached patch increases the use of StringBuilder in Classpath rather than StringBuffer.

Thanks,
Ian
Index: gnu/java/lang/reflect/TypeSignature.java
===================================================================
RCS file: 
/sources/classpath/classpath/gnu/java/lang/reflect/TypeSignature.java,v
retrieving revision 1.14
diff -u -r1.14 TypeSignature.java
--- gnu/java/lang/reflect/TypeSignature.java    2 Jul 2005 20:32:12 -0000       
1.14
+++ gnu/java/lang/reflect/TypeSignature.java    20 Oct 2007 11:10:50 -0000
@@ -239,7 +239,7 @@
   public static String getEncodingOfMethod(Method m)
   {
     Class[] paramTypes = m.getParameterTypes();
-    StringBuffer buf = new StringBuffer().append('(');
+    StringBuilder buf = new StringBuilder("(");
     for (int i = 0; i < paramTypes.length; i++)
       buf.append(getEncodingOfClass(paramTypes[i].getName(), true));
     buf.append(')').append(getEncodingOfClass(m.getReturnType().getName(),
@@ -261,7 +261,7 @@
   public static String getEncodingOfConstructor(Constructor c)
   {
     Class[] paramTypes = c.getParameterTypes();
-    StringBuffer buf = new StringBuffer().append('(');
+    StringBuilder buf = new StringBuilder("(");
     for (int i = 0; i < paramTypes.length; i++)
       buf.append(getEncodingOfClass(paramTypes[i].getName(), true));
     buf.append(")V");
Index: java/io/BufferedReader.java
===================================================================
RCS file: /sources/classpath/classpath/java/io/BufferedReader.java,v
retrieving revision 1.27
diff -u -r1.27 BufferedReader.java
--- java/io/BufferedReader.java 2 Jul 2005 20:32:37 -0000       1.27
+++ java/io/BufferedReader.java 20 Oct 2007 11:10:50 -0000
@@ -89,11 +89,6 @@
   static final int DEFAULT_BUFFER_SIZE = 8192;
 
   /**
-   * The line buffer for <code>readLine</code>.
-   */
-  private StringBuffer sbuf = null;
-
-  /**
     * Create a new <code>BufferedReader</code> that will read from the 
     * specified subordinate stream with a default buffer size of 8192 chars.
     *
@@ -455,10 +450,7 @@
            pos++;
        return str;
       }
-    if (sbuf == null)
-      sbuf = new StringBuffer(200);
-    else
-      sbuf.setLength(0);
+    StringBuilder sbuf = new StringBuilder(200);
     sbuf.append(buffer, pos, i - pos);
     pos = i;
     // We only want to return null when no characters were read before
Index: java/io/DataInputStream.java
===================================================================
RCS file: /sources/classpath/classpath/java/io/DataInputStream.java,v
retrieving revision 1.31
diff -u -r1.31 DataInputStream.java
--- java/io/DataInputStream.java        2 Jul 2005 20:32:37 -0000       1.31
+++ java/io/DataInputStream.java        20 Oct 2007 11:10:50 -0000
@@ -349,7 +349,7 @@
    */
   public final String readLine() throws IOException
   {
-    StringBuffer strb = new StringBuffer();
+    StringBuilder strb = new StringBuilder();
 
     while (true)
       {
@@ -703,7 +703,7 @@
   {
     // Give StringBuffer an initial estimated size to avoid 
     // enlarge buffer frequently
-    StringBuffer strbuf = new StringBuffer (buf.length / 2 + 2);
+    StringBuilder strbuf = new StringBuilder (buf.length / 2 + 2);
 
     for (int i = 0; i < buf.length; )
       {
Index: java/lang/StackTraceElement.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/StackTraceElement.java,v
retrieving revision 1.9
diff -u -r1.9 StackTraceElement.java
--- java/lang/StackTraceElement.java    8 Apr 2006 11:02:12 -0000       1.9
+++ java/lang/StackTraceElement.java    20 Oct 2007 11:10:50 -0000
@@ -202,7 +202,7 @@
    */
   public String toString()
   {
-    StringBuffer sb = new StringBuffer();
+    StringBuilder sb = new StringBuilder();
     if (declaringClass != null)
       {
         sb.append(declaringClass);
Index: java/lang/Throwable.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/Throwable.java,v
retrieving revision 1.30
diff -u -r1.30 Throwable.java
--- java/lang/Throwable.java    2 Jul 2005 20:32:39 -0000       1.30
+++ java/lang/Throwable.java    20 Oct 2007 11:10:50 -0000
@@ -411,7 +411,7 @@
   // different threads to get mixed up when written to the same PrintWriter.
   private String stackTraceString()
   {
-    StringBuffer sb = new StringBuffer();
+    StringBuilder sb = new StringBuilder();
 
     // Main stacktrace
     StackTraceElement[] stack = getStackTrace();
@@ -455,7 +455,7 @@
 
   // Adds to the given StringBuffer a line containing the name and
   // all stacktrace elements minus the last equal ones.
-  private static void stackTraceStringBuffer(StringBuffer sb, String name,
+  private static void stackTraceStringBuffer(StringBuilder sb, String name,
                                        StackTraceElement[] stack, int equal)
   {
     String nl = StaticData.nl;
Index: java/lang/reflect/Proxy.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/reflect/Proxy.java,v
retrieving revision 1.27
diff -u -r1.27 Proxy.java
--- java/lang/reflect/Proxy.java        10 Dec 2006 20:25:45 -0000      1.27
+++ java/lang/reflect/Proxy.java        20 Oct 2007 11:10:50 -0000
@@ -1033,7 +1033,7 @@
           code_length += 9; // new, dup_x1, swap, invokespecial, athrow
         }
       int handler_pc = code_length - 1;
-      StringBuffer signature = new StringBuffer("(");
+      StringBuilder signature = new StringBuilder("(");
       for (int j = 0; j < paramtypes.length; j++)
         signature.append(TypeSignature.getEncodingOfClass(paramtypes[j]));
       signature.append(")").append(TypeSignature.getEncodingOfClass(ret_type));
@@ -1261,8 +1261,8 @@
          // we're in the same package.
           m.flag = true;
 
-          Object[] args = {loader, qualName, bytecode, new Integer(0),
-                           new Integer(bytecode.length),
+          Object[] args = {loader, qualName, bytecode, Integer.valueOf(0),
+                           Integer.valueOf(bytecode.length),
                            Object.class.getProtectionDomain() };
           Class clazz = (Class) m.invoke(null, args);
 
@@ -1492,7 +1492,7 @@
       if (i == len)
         return str;
 
-      final StringBuffer sb = new StringBuffer(str);
+      final StringBuilder sb = new StringBuilder(str);
       sb.setLength(i);
       for ( ; i < len; i++)
         {
@@ -1533,7 +1533,7 @@
           int size = poolEntries.size() + 1;
           if (size >= 65535)
             throw new IllegalArgumentException("exceeds VM limitations");
-          i = new Integer(size);
+          i = Integer.valueOf(size);
           poolEntries.put(sequence, i);
           pool.append(sequence);
         }
Index: java/net/URI.java
===================================================================
RCS file: /sources/classpath/classpath/java/net/URI.java,v
retrieving revision 1.20
diff -u -r1.20 URI.java
--- java/net/URI.java   16 Apr 2007 14:56:37 -0000      1.20
+++ java/net/URI.java   20 Oct 2007 11:10:51 -0000
@@ -483,7 +483,7 @@
    */
   private static String quote(String str, String legalCharacters)
   {
-    StringBuffer sb = new StringBuffer(str.length());
+    StringBuilder sb = new StringBuilder(str.length());
     for (int i = 0; i < str.length(); i++)
       {
        char c = str.charAt(i);
@@ -778,8 +778,8 @@
        This follows the algorithm in section 5.2.4. of RFC3986,
        but doesn't modify the input buffer.
     */
-    StringBuffer input = new StringBuffer(relativePath);
-    StringBuffer output = new StringBuffer();
+    StringBuilder input = new StringBuilder(relativePath);
+    StringBuilder output = new StringBuilder();
     int start = 0;
     while (start < input.length())
       {
@@ -853,7 +853,7 @@
    *
    * @param buffer the buffer containing the path.
    */
-  private void removeLastSegment(StringBuffer buffer)
+  private void removeLastSegment(StringBuilder buffer)
   {
     int lastSlash = buffer.lastIndexOf("/");
     if (lastSlash == -1)
@@ -899,7 +899,7 @@
              path = "";
            if (! (path.startsWith("/")))
              {
-               StringBuffer basepath = new StringBuffer(this.path);
+               StringBuilder basepath = new StringBuilder(this.path);
                int i = this.path.lastIndexOf('/');
 
                if (i >= 0)
@@ -1315,7 +1315,8 @@
            int hCompare = host.compareTo(uri.getHost());
            if (hCompare != 0)
              return hCompare;
-           return new Integer(port).compareTo(new Integer(uri.getPort()));
+       int uriPort = uri.getPort();
+       return (uriPort == port) ? 0 : (uriPort < port) ? -1 : 1;
          }
       }
     if (rawPath == null && uri.getRawPath() != null)
@@ -1381,8 +1382,8 @@
   {
     String strRep = toString();
     boolean inNonAsciiBlock = false;
-    StringBuffer buffer = new StringBuffer();
-    StringBuffer encBuffer = null;
+    StringBuilder buffer = new StringBuilder();
+    StringBuilder encBuffer = null;
     for (int i = 0; i < strRep.length(); i++)
       {
        char c = strRep.charAt(i);
@@ -1399,7 +1400,7 @@
          {
            if (!inNonAsciiBlock)
              {
-               encBuffer = new StringBuffer();
+               encBuffer = new StringBuilder();
                inNonAsciiBlock = true;
              }
            encBuffer.append(c);
@@ -1421,7 +1422,7 @@
   {
     try
       {
-       StringBuffer sb = new StringBuffer(); 
+       StringBuilder sb = new StringBuilder(); 
        // this is far from optimal, but it works
        byte[] utf8 = str.getBytes("utf-8");
        for (int j = 0; j < utf8.length; j++)
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /sources/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.54
diff -u -r1.54 URLClassLoader.java
--- java/net/URLClassLoader.java        21 Jun 2007 05:43:38 -0000      1.54
+++ java/net/URLClassLoader.java        20 Oct 2007 11:10:51 -0000
@@ -452,7 +452,7 @@
   {
     // Compute the name of the package as it may appear in the
     // Manifest.
-    StringBuffer xform = new StringBuffer(name);
+    StringBuilder xform = new StringBuilder(name);
     for (int i = xform.length () - 1; i >= 0; --i)
       if (xform.charAt(i) == '.')
        xform.setCharAt(i, '/');
@@ -641,7 +641,7 @@
       {
        if (thisString == null)
          {
-           StringBuffer sb = new StringBuffer();
+           StringBuilder sb = new StringBuilder();
            sb.append(this.getClass().getName());
            sb.append("{urls=[" );
            URL[] thisURLs = getURLs();
Index: java/net/URLEncoder.java
===================================================================
RCS file: /sources/classpath/classpath/java/net/URLEncoder.java,v
retrieving revision 1.14
diff -u -r1.14 URLEncoder.java
--- java/net/URLEncoder.java    2 Jul 2005 20:32:39 -0000       1.14
+++ java/net/URLEncoder.java    20 Oct 2007 11:10:51 -0000
@@ -113,7 +113,7 @@
     int start = 0;
     int i = 0;
 
-    StringBuffer result = new StringBuffer(length);
+    StringBuilder result = new StringBuilder(length);
     while (true)
       {
        while (i < length && isSafe(s.charAt(i)))
Index: java/text/SimpleDateFormat.java
===================================================================
RCS file: /sources/classpath/classpath/java/text/SimpleDateFormat.java,v
retrieving revision 1.55
diff -u -r1.55 SimpleDateFormat.java
--- java/text/SimpleDateFormat.java     20 Jan 2007 03:31:00 -0000      1.55
+++ java/text/SimpleDateFormat.java     20 Oct 2007 11:10:51 -0000
@@ -139,9 +139,9 @@
      */
     public String toString()
     {
-      StringBuffer builder;
+      StringBuilder builder;
 
-      builder = new StringBuffer(getClass().getName());
+      builder = new StringBuilder(getClass().getName());
       builder.append("[field=");
       builder.append(field);
       builder.append(", size=");
@@ -322,7 +322,7 @@
                    // Look for the terminating quote.  However, if we
                    // see a '', that represents a literal quote and
                    // we must iterate.
-                   StringBuffer buf = new StringBuffer();
+                   StringBuilder buf = new StringBuilder();
                    int oldPos = i + 1;
                    do
                      {
@@ -346,7 +346,7 @@
            else
              {
                // A special character
-               tokens.add(new Character(thisChar));
+               tokens.add(Character.valueOf(thisChar));
              }
          }
        else
@@ -372,7 +372,7 @@
    */
   public String toString() 
   {
-    StringBuffer output = new StringBuffer(getClass().getName());
+    StringBuilder output = new StringBuilder(getClass().getName());
     output.append("[tokens=");
     output.append(tokens);
     output.append(", formatData=");
@@ -554,7 +554,7 @@
                                           String oldChars, String newChars)
   {
     int len = pattern.length();
-    StringBuffer buf = new StringBuffer(len);
+    StringBuilder buf = new StringBuilder(len);
     boolean quoted = false;
     for (int i = 0;  i < len;  i++)
       {
@@ -1279,12 +1279,12 @@
 
        // advance the index
        pos.setIndex(pos.getIndex() + matcher.end());
-       return new Integer(offset);
+       return Integer.valueOf(offset);
       }
     else if (zoneString.startsWith("GMT"))
       {
        pos.setIndex(pos.getIndex() + 3);
-       return new Integer(0);
+       return Integer.valueOf(0);
       }
     return null;
   }
Index: java/util/AbstractMap.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/AbstractMap.java,v
retrieving revision 1.32
diff -u -r1.32 AbstractMap.java
--- java/util/AbstractMap.java  28 Dec 2006 03:04:42 -0000      1.32
+++ java/util/AbstractMap.java  20 Oct 2007 11:10:51 -0000
@@ -524,7 +524,7 @@
   public String toString()
   {
     Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
-    StringBuffer r = new StringBuffer("{");
+    StringBuilder r = new StringBuilder("{");
     for (int pos = size(); pos > 0; pos--)
       {
         Map.Entry<K, V> entry = entries.next();
Index: java/util/Calendar.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/Calendar.java,v
retrieving revision 1.52
diff -u -r1.52 Calendar.java
--- java/util/Calendar.java     29 Dec 2006 02:17:58 -0000      1.52
+++ java/util/Calendar.java     20 Oct 2007 11:10:51 -0000
@@ -1328,8 +1328,8 @@
    */
   public String toString()
   {
-    StringBuffer sb = new StringBuffer();
-    sb.append(getClass().getName()).append('[');
+    StringBuilder sb = new StringBuilder(getClass().getName());
+    sb.append('[');
     sb.append("time=");
     if (isTimeSet)
       sb.append(time);
Index: java/util/Date.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/Date.java,v
retrieving revision 1.26
diff -u -r1.26 Date.java
--- java/util/Date.java 23 Feb 2007 15:50:04 -0000      1.26
+++ java/util/Date.java 20 Oct 2007 11:10:51 -0000
@@ -722,7 +722,7 @@
     boolean localTimezone = true;
 
     // Trim out any nested stuff in parentheses now to make parsing easier.
-    StringBuffer buf = new StringBuffer();
+    StringBuilder buf = new StringBuilder();
     int parenNesting = 0;
     int len = string.length();
     for (int i = 0;  i < len;  i++)
Index: java/util/Hashtable.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/Hashtable.java,v
retrieving revision 1.42
diff -u -r1.42 Hashtable.java
--- java/util/Hashtable.java    6 Apr 2007 17:44:10 -0000       1.42
+++ java/util/Hashtable.java    20 Oct 2007 11:10:51 -0000
@@ -579,7 +579,7 @@
     // would repeatedly re-lock/release the monitor, we directly use the
     // unsynchronized EntryIterator instead.
     Iterator<Map.Entry<K, V>> entries = new EntryIterator();
-    StringBuffer r = new StringBuffer("{");
+    StringBuilder r = new StringBuilder("{");
     for (int pos = size; pos > 0; pos--)
       {
         r.append(entries.next());

Reply via email to