groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Trivial refactoring: Use `StringBuilder` instead
Date Wed, 03 Jan 2018 00:58:14 GMT
Repository: groovy
Updated Branches:
  refs/heads/master e0404356c -> 9b1fb03d6


Trivial refactoring: Use `StringBuilder` instead


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9b1fb03d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9b1fb03d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9b1fb03d

Branch: refs/heads/master
Commit: 9b1fb03d67cdd49c6de20b26d6d300adaa54f52a
Parents: e040435
Author: sunlan <sunlan@apache.org>
Authored: Wed Jan 3 08:57:06 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Wed Jan 3 08:57:59 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/MetaMethod.java         |  4 ++--
 .../org/codehaus/groovy/antlr/SourceBuffer.java     | 16 ++++++++--------
 .../codehaus/groovy/classgen/AsmClassGenerator.java |  8 ++++----
 .../main/groovy/groovy/ui/text/GroovyFilter.java    |  2 +-
 .../org/codehaus/groovy/tools/shell/Groovysh.groovy |  2 +-
 .../StreamingMarkupWriter.java                      |  2 +-
 6 files changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/src/main/groovy/groovy/lang/MetaMethod.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/MetaMethod.java b/src/main/groovy/groovy/lang/MetaMethod.java
index 3051675..c58d6b7 100644
--- a/src/main/groovy/groovy/lang/MetaMethod.java
+++ b/src/main/groovy/groovy/lang/MetaMethod.java
@@ -280,9 +280,9 @@ public abstract class MetaMethod extends ParameterTypes implements Cloneable
{
           String name = getName();
           CachedClass declaringClass = getDeclaringClass();
           if (Modifier.isPrivate(getModifiers()))
-            mopName = new StringBuffer().append("this$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
+            mopName = new StringBuilder("this$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
           else 
-            mopName = new StringBuffer().append("super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
+            mopName = new StringBuilder("super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
         }
         return mopName;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java b/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java
index 6b45e50..558370f 100644
--- a/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java
+++ b/src/main/java/org/codehaus/groovy/antlr/SourceBuffer.java
@@ -28,14 +28,14 @@ import java.util.List;
  * @author <a href="mailto:groovy@ross-rayner.com">Jeremy Rayner</a>
  */
 public class SourceBuffer {
-    private final List lines;
-    private StringBuffer current;
+    private final List<StringBuilder> lines;
+    private StringBuilder current;
 
     public SourceBuffer() {
-        lines = new ArrayList();
-        //lines.add(new StringBuffer()); // dummy row for position [0] in the List
+        lines = new ArrayList<StringBuilder>();
+        //lines.add(new StringBuilder()); // dummy row for position [0] in the List
 
-        current = new StringBuffer();
+        current = new StringBuilder();
         lines.add(current);
     }
 
@@ -66,9 +66,9 @@ public class SourceBuffer {
         if (endLine > lines.size()) { endLine = lines.size(); }
 
         // obtain the snippet from the buffer within specified bounds
-        StringBuffer snippet = new StringBuffer();
+        StringBuilder snippet = new StringBuilder();
         for (int i = startLine - 1; i < endLine;i++) {
-            String line = ((StringBuffer)lines.get(i)).toString();
+            String line = ((StringBuilder)lines.get(i)).toString();
             if (startLine == endLine) {
                 // reset any out of bounds requests (again)
                 if (startColumn > line.length()) { startColumn = line.length();}
@@ -104,7 +104,7 @@ public class SourceBuffer {
             current.append((char)c);
         }
         if (c == '\n') {
-            current = new StringBuffer();
+            current = new StringBuilder();
             lines.add(current);
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 3d1b841..dbbcdcb 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -433,11 +433,11 @@ public class AsmClassGenerator extends ClassGenerator {
                     tracer.p.print(p);
                     p.flush();
                 }
-                StringBuffer outBuffer = new StringBuffer();
+                StringBuilder outBuffer = new StringBuilder();
                 outBuffer.append("ASM reporting processing error for ");
-                outBuffer.append(controller.getClassNode().toString()+"#"+node.getName());
-                outBuffer.append(" with signature "+node.getTypeDescriptor());
-                outBuffer.append(" in "+sourceFile+":"+node.getLineNumber());
+                outBuffer.append(controller.getClassNode().toString() + "#" + node.getName());
+                outBuffer.append(" with signature " + node.getTypeDescriptor());
+                outBuffer.append(" in " + sourceFile + ":" + node.getLineNumber());
                 if (writer != null) {
                     outBuffer.append("\nLast known generated bytecode in last generated method
or constructor:\n");
                     outBuffer.append(writer);

http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/subprojects/groovy-console/src/main/groovy/groovy/ui/text/GroovyFilter.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/GroovyFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/GroovyFilter.java
index 6eaa9e9..baa29e1 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/text/GroovyFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/text/GroovyFilter.java
@@ -204,7 +204,7 @@ public class GroovyFilter extends StructuredSyntaxDocumentFilter {
 
         private StyledDocument doc;
         private final Segment segment = new Segment();
-        private final StringBuffer buffer = new StringBuffer();
+        private final StringBuilder buffer = new StringBuilder();
 
         public void actionPerformed(ActionEvent ae) {
             JTextComponent tComp = (JTextComponent) ae.getSource();

http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
index 71950dd..5845a4d 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Groovysh.groovy
@@ -508,7 +508,7 @@ try {$COLLECTED_BOUND_VARS_MAP_VARNAME[\"$varname\"] = $varname;
 
                 def trace = cause.stackTrace
 
-                def buff = new StringBuffer()
+                def buff = new StringBuilder()
 
                 boolean doBreak = false
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9b1fb03d/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java
b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java
index 21d467e..6f35a52 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/streamingmarkupsupport/StreamingMarkupWriter.java
@@ -33,7 +33,7 @@ public class StreamingMarkupWriter extends Writer {
     protected final CharsetEncoder encoder;
     protected boolean writingAttribute = false;
     protected boolean haveHighSurrogate = false;
-    protected StringBuffer surrogatePair = new StringBuffer(2);
+    protected StringBuilder surrogatePair = new StringBuilder(2);
     private boolean useDoubleQuotes;
     private final Writer escapedWriter = new Writer() {
         /* (non-Javadoc)


Mime
View raw message