[cp-patches] [gnu_andrew at member.fsf.org: FYI: PR21869 More StringBuilder replacements]

Andrew John Hughes gnu_andrew at member.fsf.org
Mon Apr 28 21:30:29 UTC 2008


----- Forwarded message from Andrew John Hughes <gnu_andrew at member.fsf.org> -----

Date: Mon, 28 Apr 2008 20:52:04 +0100
From: Andrew John Hughes <gnu_andrew at member.fsf.org>
To: classpath-patches at gnu.org
Subject: FYI: PR21869 More StringBuilder replacements
User-Agent: Mutt/1.5.16 (2007-06-09)

The continued removal of StringBuffer usage where possible...

ChangeLog:

2008-04-28  Andrew John Hughes  <gnu_andrew at member.fsf.org>

	PR classpath/21869
	* util/XMLWriter.java,
	* xpath/ArithmeticExpr.java,
	* xpath/ConcatFunction.java,
	* xpath/Expr.java,
	* xpath/FunctionCall.java,
	* xpath/NormalizeSpaceFunction.java,
	* xpath/Selector.java,
	* xpath/Steps.java,
	* xpath/TranslateFunction.java,
	* xpath/VariableReference.java,
	* xpath/XPathTokenizer.java:
	Swap use of StringBuffer for CPStringBuilder.

-- 
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/xml/util/XMLWriter.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/util/XMLWriter.java,v
retrieving revision 1.3
diff -u -r1.3 XMLWriter.java
--- gnu/xml/util/XMLWriter.java	16 Jan 2006 16:23:20 -0000	1.3
+++ gnu/xml/util/XMLWriter.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.util;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.io.BufferedWriter;
 import java.io.CharConversionException;
 import java.io.IOException;
@@ -152,7 +154,7 @@
     private String		eol = sysEOL;
 
     private short		dangerMask;
-    private StringBuffer	stringBuf;
+    private CPStringBuilder	stringBuf;
     private Locator		locator;
     private ErrorHandler	errHandler;
 
@@ -289,7 +291,7 @@
 	    }
 
 	    if (dangerMask != 0)
-		stringBuf = new StringBuffer ();
+		stringBuf = new CPStringBuilder ();
 	}
 
 	this.encoding = encoding;
Index: gnu/xml/xpath/ArithmeticExpr.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/ArithmeticExpr.java,v
retrieving revision 1.4
diff -u -r1.4 ArithmeticExpr.java
--- gnu/xml/xpath/ArithmeticExpr.java	28 Aug 2005 09:05:46 -0000	1.4
+++ gnu/xml/xpath/ArithmeticExpr.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import javax.xml.namespace.QName;
 import org.w3c.dom.Node;
 
@@ -139,7 +141,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     buf.append(lhs);
     buf.append(' ');
     switch (op)
Index: gnu/xml/xpath/ConcatFunction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/ConcatFunction.java,v
retrieving revision 1.3
diff -u -r1.3 ConcatFunction.java
--- gnu/xml/xpath/ConcatFunction.java	9 Jul 2005 20:38:35 -0000	1.3
+++ gnu/xml/xpath/ConcatFunction.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -61,7 +63,7 @@
 
   public Object evaluate(Node context, int pos, int len)
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     for (Iterator i = args.iterator(); i.hasNext(); )
       {
         Expr arg = (Expr) i.next();
@@ -96,7 +98,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer("concat(");
+    CPStringBuilder buf = new CPStringBuilder("concat(");
     int len = args.size();
     for (int i = 0; i < len; i++)
       {
Index: gnu/xml/xpath/Expr.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Expr.java,v
retrieving revision 1.6
diff -u -r1.6 Expr.java
--- gnu/xml/xpath/Expr.java	9 Sep 2006 12:12:48 -0000	1.6
+++ gnu/xml/xpath/Expr.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.io.IOException;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
@@ -471,7 +473,7 @@
    */
   public static String stringValue(Collection nodeSet)
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     for (Iterator i = nodeSet.iterator(); i.hasNext(); )
       {
         buf.append(stringValue((Node) i.next()));
@@ -494,7 +496,7 @@
       case Node.DOCUMENT_NODE: // 5.1 Root Node
       case Node.DOCUMENT_FRAGMENT_NODE:
       case Node.ELEMENT_NODE: // 5.2 Element Nodes
-        StringBuffer buf = new StringBuffer();
+        CPStringBuilder buf = new CPStringBuilder();
         for (Node ctx = node.getFirstChild(); ctx != null;
              ctx = ctx.getNextSibling())
           {
Index: gnu/xml/xpath/FunctionCall.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/FunctionCall.java,v
retrieving revision 1.4
diff -u -r1.4 FunctionCall.java
--- gnu/xml/xpath/FunctionCall.java	9 Jul 2005 20:38:35 -0000	1.4
+++ gnu/xml/xpath/FunctionCall.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -144,7 +146,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     buf.append(name);
     buf.append('(');
     int len = args.size();
Index: gnu/xml/xpath/NormalizeSpaceFunction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/NormalizeSpaceFunction.java,v
retrieving revision 1.3
diff -u -r1.3 NormalizeSpaceFunction.java
--- gnu/xml/xpath/NormalizeSpaceFunction.java	9 Jul 2005 20:38:36 -0000	1.3
+++ gnu/xml/xpath/NormalizeSpaceFunction.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.List;
 import java.util.StringTokenizer;
 import javax.xml.namespace.QName;
@@ -74,7 +76,7 @@
     Object val = (arg == null) ? null : arg.evaluate(context, pos, len);
     String s = _string(context, val);
     StringTokenizer st = new StringTokenizer(s, " \t\r\n");
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     if (st.hasMoreTokens())
       {
         buf.append(st.nextToken()); 
Index: gnu/xml/xpath/Selector.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Selector.java,v
retrieving revision 1.8
diff -u -r1.8 Selector.java
--- gnu/xml/xpath/Selector.java	16 Jan 2006 16:23:20 -0000	1.8
+++ gnu/xml/xpath/Selector.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -431,7 +433,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     switch (axis)
       {
       case ANCESTOR:
Index: gnu/xml/xpath/Steps.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Steps.java,v
retrieving revision 1.3
diff -u -r1.3 Steps.java
--- gnu/xml/xpath/Steps.java	9 Jul 2005 20:38:36 -0000	1.3
+++ gnu/xml/xpath/Steps.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -234,7 +236,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     Iterator i = path.iterator();
     Expr expr = (Expr) i.next();
     if (!(expr instanceof Root))
Index: gnu/xml/xpath/TranslateFunction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/TranslateFunction.java,v
retrieving revision 1.3
diff -u -r1.3 TranslateFunction.java
--- gnu/xml/xpath/TranslateFunction.java	9 Jul 2005 20:38:36 -0000	1.3
+++ gnu/xml/xpath/TranslateFunction.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.util.List;
 import javax.xml.namespace.QName;
 import org.w3c.dom.Node;
@@ -86,7 +88,7 @@
     String string = _string(context, val1);
     String search = _string(context, val2);
     String replace = _string(context, val3);
-    StringBuffer buf = new StringBuffer();
+    CPStringBuilder buf = new CPStringBuilder();
     int l1 = string.length();
     int l2 = search.length();
     int l3 = replace.length();
@@ -110,7 +112,7 @@
             buf.append(c);
           } 
       } 
-    return new String(buf);
+    return buf.toString();
   }
 
   public Expr clone(Object context)
Index: gnu/xml/xpath/VariableReference.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/VariableReference.java,v
retrieving revision 1.3
diff -u -r1.3 VariableReference.java
--- gnu/xml/xpath/VariableReference.java	9 Jul 2005 20:38:36 -0000	1.3
+++ gnu/xml/xpath/VariableReference.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import javax.xml.namespace.QName;
 import javax.xml.xpath.XPathVariableResolver;
 import org.w3c.dom.Node;
@@ -86,7 +88,7 @@
 
   public String toString()
   {
-    StringBuffer buf = new StringBuffer("$");
+    CPStringBuilder buf = new CPStringBuilder("$");
     String prefix = name.getPrefix();
     if (prefix != null && !"".equals(prefix))
       {
Index: gnu/xml/xpath/XPathTokenizer.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/XPathTokenizer.java,v
retrieving revision 1.2
diff -u -r1.2 XPathTokenizer.java
--- gnu/xml/xpath/XPathTokenizer.java	2 Jul 2005 20:32:22 -0000	1.2
+++ gnu/xml/xpath/XPathTokenizer.java	28 Apr 2008 19:48:48 -0000
@@ -37,6 +37,8 @@
 
 package gnu.xml.xpath;
 
+import gnu.java.lang.CPStringBuilder;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.Reader;
@@ -314,7 +316,7 @@
   XPathToken consume_literal (int delimiter)
     throws IOException
   {
-    StringBuffer buf = new StringBuffer ();
+    CPStringBuilder buf = new CPStringBuilder ();
     while (true)
       {
         int c = in.read ();
@@ -336,7 +338,7 @@
   XPathToken consume_digits (int c)
     throws IOException
   {
-    StringBuffer buf = new StringBuffer ();
+    CPStringBuilder buf = new CPStringBuilder ();
     buf.append ((char) c);
     while (true)
       {
@@ -357,7 +359,7 @@
   XPathToken consume_name (int c)
     throws IOException
   {
-    StringBuffer buf = new StringBuffer ();
+    CPStringBuilder buf = new CPStringBuilder ();
     buf.append ((char) c);
     while (true)
       {


----- End forwarded message -----

-- 
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



More information about the Classpath-patches mailing list