Apologies this was committed yesterday and I should have posted the patch here earlier.

Ian

CVSROOT:        /sources/classpath
Module name:    classpath
Changes by:     Ian Rogers <irogers>      08/02/05 14:59:06

Modified files:
        gnu/java/lang/reflect: TypeSignature.java
        java/io        : BufferedReader.java DataInputStream.java
        java/lang      : StackTraceElement.java Throwable.java
        java/lang/reflect: Proxy.java
        java/net       : URI.java URLClassLoader.java URLEncoder.java
        java/text      : SimpleDateFormat.java
        java/util      : AbstractMap.java Calendar.java Date.java
                         Hashtable.java

Log message:
        2008-02-05  Ian Rogers  <[EMAIL PROTECTED]>
        
                * gnu/java/lang/reflect/TypeSignature.java
                * java/io/BufferedReader.java
                * java/io/DataInputStream.java
                * java/lang/StackTraceElement.java
                * java/lang/Throwable.java
                * java/lang/reflect/Proxy.java
                * java/net/URI.java
                * java/net/URLClassLoader.java
                * java/net/URLEncoder.java
                * java/text/SimpleDateFormat.java
                * java/util/AbstractMap.java
                * java/util/Calendar.java
                * java/util/Date.java
                * java/util/Hashtable.java
                Use StringBuilder in preference to StringBuffer
                * java/util/Calendar.java
                * java/util/Hashtable.java
                Make private fields that can be final, final
                * java/net/URI.java
                Avoid creating Integer objects for the sake of comparison
                * java/lang/reflect/Proxy.java
                * java/text/SimpleDateFormat.java
                Swap use of "new Character/Integer" to use of valueOf methods

Index: gnu/java/lang/reflect/TypeSignature.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/lang/reflect/TypeSignature.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- gnu/java/lang/reflect/TypeSignature.java 2 Jul 2005 20:32:12 -0000 1.14 +++ gnu/java/lang/reflect/TypeSignature.java 5 Feb 2008 14:59:04 -0000 1.15
@@ -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
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- java/io/BufferedReader.java 2 Jul 2005 20:32:37 -0000       1.27
+++ java/io/BufferedReader.java 5 Feb 2008 14:59:04 -0000       1.28
@@ -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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- java/io/DataInputStream.java        29 Jan 2008 22:30:44 -0000      1.32
+++ java/io/DataInputStream.java        5 Feb 2008 14:59:04 -0000       1.33
@@ -350,7 +350,7 @@
    */
   public final String readLine() throws IOException
   {
-    StringBuffer strb = new StringBuffer();
+    StringBuilder strb = new StringBuilder();

     while (true)
       {
@@ -747,7 +747,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
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- java/lang/StackTraceElement.java    8 Apr 2006 11:02:12 -0000       1.9
+++ java/lang/StackTraceElement.java    5 Feb 2008 14:59:05 -0000       1.10
@@ -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
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- java/lang/Throwable.java    2 Jul 2005 20:32:39 -0000       1.30
+++ java/lang/Throwable.java    5 Feb 2008 14:59:05 -0000       1.31
@@ -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.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- java/lang/reflect/Proxy.java        1 Nov 2007 20:06:57 -0000       1.28
+++ java/lang/reflect/Proxy.java        5 Feb 2008 14:59:05 -0000       1.29
@@ -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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- java/net/URI.java   21 Jan 2008 20:09:56 -0000      1.21
+++ java/net/URI.java   5 Feb 2008 14:59:05 -0000       1.22
@@ -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)
@@ -1321,7 +1321,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)
@@ -1387,8 +1388,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);
@@ -1405,7 +1406,7 @@
          {
            if (!inNonAsciiBlock)
              {
-               encBuffer = new StringBuffer();
+               encBuffer = new StringBuilder();
                inNonAsciiBlock = true;
              }
            encBuffer.append(c);
@@ -1427,7 +1428,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
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- java/net/URLClassLoader.java        21 Jun 2007 05:43:38 -0000      1.54
+++ java/net/URLClassLoader.java        5 Feb 2008 14:59:05 -0000       1.55
@@ -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
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- java/net/URLEncoder.java    2 Jul 2005 20:32:39 -0000       1.14
+++ java/net/URLEncoder.java    5 Feb 2008 14:59:05 -0000       1.15
@@ -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
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- java/text/SimpleDateFormat.java     20 Jan 2007 03:31:00 -0000      1.55
+++ java/text/SimpleDateFormat.java     5 Feb 2008 14:59:05 -0000       1.56
@@ -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
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- java/util/AbstractMap.java  28 Dec 2006 03:04:42 -0000      1.32
+++ java/util/AbstractMap.java  5 Feb 2008 14:59:05 -0000       1.33
@@ -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.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- java/util/Calendar.java     7 Jan 2008 21:11:25 -0000       1.53
+++ java/util/Calendar.java     5 Feb 2008 14:59:05 -0000       1.54
@@ -572,7 +572,7 @@
* Cache of locale->calendar-class mappings. This avoids having to do a ResourceBundle
    * lookup for every getInstance call.
    */
-  private static HashMap<Locale,Class> cache = new HashMap<Locale,Class>();
+ private static final HashMap<Locale,Class> cache = new HashMap<Locale,Class>();

   /** Preset argument types for calendar-class constructor lookup.  */
   private static Class[] ctorArgTypes = new Class[]
@@ -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
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- java/util/Date.java 23 Feb 2007 15:50:04 -0000      1.26
+++ java/util/Date.java 5 Feb 2008 14:59:06 -0000       1.27
@@ -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
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- java/util/Hashtable.java    6 Apr 2007 17:44:10 -0000       1.42
+++ java/util/Hashtable.java    5 Feb 2008 14:59:06 -0000       1.43
@@ -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());
@@ -1088,7 +1088,7 @@
      * <code>next()</code> gives a different result, by returning just
      * the key rather than the whole element.
      */
-    private EntryIterator iterator;
+    private final EntryIterator iterator;

     /**
      * Construct a new KeyIterator
@@ -1153,7 +1153,7 @@
      * <code>next()</code> gives a different result, by returning just
      * the value rather than the whole element.
      */
-    private EntryIterator iterator;
+    private final EntryIterator iterator;

     /**
      * Construct a new KeyIterator
@@ -1294,7 +1294,7 @@
* <code>nextElement()</code> gives a different result, by returning just
      * the key rather than the whole element.
      */
-    private EntryEnumerator enumerator;
+    private final EntryEnumerator enumerator;

     /**
      * Construct a new KeyEnumerator
@@ -1355,7 +1355,7 @@
* <code>nextElement()</code> gives a different result, by returning just
      * the value rather than the whole element.
      */
-    private EntryEnumerator enumerator;
+    private final EntryEnumerator enumerator;

     /**
      * Construct a new ValueEnumerator


Reply via email to