7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator
authoranthony
Tue, 01 Nov 2011 18:03:56 +0300
changeset 10872 4c64f54e8e79
parent 10871 c0aeb0b14df1
child 10873 b4a797aab8d1
7105529: XAWT: Optimize getFieldsAsString() methods generated by WrapperGenerator Summary: Replace string concatenation with StringBuilder.append() Reviewed-by: anthony, son Contributed-by: Federico Tello Gentile <federicotg@gmail.com>
jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java
--- a/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java	Tue Nov 01 18:01:58 2011 +0300
+++ b/jdk/src/solaris/classes/sun/awt/X11/generator/WrapperGenerator.java	Tue Nov 01 18:03:56 2011 +0300
@@ -678,7 +678,7 @@
     public void writeToString(StructType stp, PrintWriter pw) {
         int type;
         pw.println("\n\n\tString getName() {\n\t\treturn \"" + stp.getName()+ "\"; \n\t}");
-        pw.println("\n\n\tString getFieldsAsString() {\n\t\tString ret=\"\";\n");
+        pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n");
 
         for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
             AtomicType tp = (AtomicType) e.nextElement();
@@ -688,24 +688,24 @@
             if ((name != null) && (name.length() > 0))
             {
                 if (type == AtomicType.TYPE_ATOM) {
-                    pw.println("\t\tret += \"\"+\"" + name + " = \" + XAtom.get(get_" + name + "()) +\", \";");
+                    pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");");
                 } else if (name.equals("type")) {
-                    pw.println("\t\tret += \"\"+\"type = \" + XlibWrapper.eventToString[get_type()] +\", \";");
+                    pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");");
                 } else if (name.equals("window")){
-                    pw.println("\t\tret += \"\"+\"window = \" + getWindow(get_window()) + \", \";");
+                    pw.println("\t\tret.append(\"window = \" ).append( getWindow(get_window()) ).append(\", \");");
                 } else if (type == AtomicType.TYPE_ARRAY) {
-                    pw.print("\t\tret += \"{\"");
+                    pw.print("\t\tret.append(\"{\")");
                     for (int i = 0; i < tp.getArrayLength(); i++) {
-                        pw.print(" + get_" + name + "(" + i + ") + \" \"");
+                        pw.print("\n\t\t.append( get_" + name + "(" + i + ") ).append(\" \")");
                     }
-                    pw.println(" + \"}\";");
+                    pw.println(".append( \"}\");");
                 } else {
-                    pw.println("\t\tret += \"\"+\"" + name +" = \" + get_"+ name+"() +\", \";");
+                    pw.println("\t\tret.append(\"" + name +" = \").append( get_"+ name+"() ).append(\", \");");
                 }
             }
 
         }
-        pw.println("\t\treturn ret;\n\t}\n\n");
+        pw.println("\t\treturn ret.toString();\n\t}\n\n");
     }
 
     public void writeStubs(StructType stp, PrintWriter pw) {