Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 7d1654a92 -> 77dde9ced


Fix some potential performance issues

(cherry picked from commit b8a52eb)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: d46ba2d782bf02374ec1fec4d6c88a01322734ff
Parents: 7d1654a
Author: danielsun1106 <realblue...@hotmail.com>
Authored: Tue Feb 20 03:00:48 2018 +0800
Committer: danielsun1106 <realblue...@hotmail.com>
Committed: Tue Feb 20 03:42:14 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/classgen/GeneratorContext.java  |  2 +-
 .../org/codehaus/groovy/control/CompilationUnit.java    |  4 +---
 .../org/codehaus/groovy/control/ResolveVisitor.java     | 12 ++++++------
 .../org/codehaus/groovy/reflection/ReflectionCache.java |  2 +-
 .../codehaus/groovy/runtime/ResourceGroovyMethods.java  |  4 +---
 .../codehaus/groovy/tools/javac/JavacJavaCompiler.java  |  3 +--
 .../transform/stc/TraitTypeCheckingExtension.java       |  2 +-
 7 files changed, 12 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java 
b/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
index dd318bd..1204dfa 100644
--- a/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
+++ b/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
@@ -115,7 +115,7 @@ public class GeneratorContext {
                 }
             }
         }
-        if(b == null) return name.toString();
+        if(b == null) return name;
         if (lastEscape == -1) throw new GroovyBugError("unexpected escape char 
control flow in "+name);
         b.append(name, lastEscape + 1, l);
         return b.toString();

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java 
b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index a766784..b47a653 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -1026,9 +1026,7 @@ public class CompilationUnit extends ProcessingUnit {
     private List<ClassNode> getPrimaryClassNodes(boolean sort) {
         List<ClassNode> unsorted = new ArrayList<ClassNode>();
         for (ModuleNode module : this.ast.getModules()) {
-            for (ClassNode classNode : module.getClasses()) {
-                unsorted.add(classNode);
-            }
+            unsorted.addAll(module.getClasses());
         }
 
         if (!sort) return unsorted;

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java 
b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index fe96714..922c528 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -762,7 +762,7 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
 
     private static String lookupClassName(PropertyExpression pe) {
         boolean doInitialClassTest=true;
-        String name = "";
+        StringBuilder name = new StringBuilder(32);
         // this loop builds a name from right to left each name part
         // separated by "."
         for (Expression it = pe; it != null; it = ((PropertyExpression) 
it).getObjectExpression()) {
@@ -782,9 +782,9 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
                     // field bar.
                     if (!testVanillaNameForClass(varName)) return null;
                     doInitialClassTest = false;
-                    name = varName;
+                    name = new StringBuilder(varName);
                 } else {
-                    name = varName + "." + name;
+                    name.insert(0, varName + ".");
                 }
                 break;
             }
@@ -808,14 +808,14 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
                     // field bar.
                     if (!testVanillaNameForClass(propertyPart)) return null;
                     doInitialClassTest= false;
-                    name = propertyPart;
+                    name = new StringBuilder(propertyPart);
                 } else {
-                    name = propertyPart + "." + name;
+                    name.insert(0, propertyPart + ".");
                 }
             }
         }
         if (name.length() == 0) return null;
-        return name;
+        return name.toString();
     }
 
     // iterate from the inner most to the outer and check for classes

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java 
b/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
index 372a0a5..c9ea871 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionCache.java
@@ -47,7 +47,7 @@ public class ReflectionCache {
     public static String getMOPMethodName(CachedClass declaringClass, String 
name, boolean useThis) {
         TripleKeyHashMap.Entry mopNameEntry = 
mopNames.getOrPut(declaringClass, name, Boolean.valueOf(useThis));
         if (mopNameEntry.value == null) {
-            mopNameEntry.value = new StringBuffer().append(useThis ? "this$" : 
"super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
+            mopNameEntry.value = new StringBuilder().append(useThis ? "this$" 
: 
"super$").append(declaringClass.getSuperClassDistance()).append("$").append(name).toString();
         }
         return (String) mopNameEntry.value;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index c869523..789b275 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -1716,9 +1716,7 @@ public class ResourceGroovyMethods extends 
DefaultGroovyMethodsSupport {
         }
 
         // fill it up path with parts which were not equal
-        for (int i = same; i < toPathStack.length; i++) {
-            relativePathStack.add(toPathStack[i]);
-        }
+        relativePathStack.addAll(Arrays.asList(toPathStack).subList(same, 
toPathStack.length));
 
         return getPath(relativePathStack);
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java 
b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
index a705ecf..bfed227 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
@@ -165,9 +165,8 @@ public class JavacJavaCompiler implements JavaCompiler {
                 // ignore it
             }
 
-            StringBuilder resultPath = new 
StringBuilder(DefaultGroovyMethods.join((Iterable) paths, File.pathSeparator));
             paras.add("-classpath");
-            paras.add(resultPath.toString());
+            paras.add(DefaultGroovyMethods.join((Iterable) paths, 
File.pathSeparator));
         }
 
         // files to compile

http://git-wip-us.apache.org/repos/asf/groovy/blob/d46ba2d7/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
 
b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
index 9bc93b5..4a108d9 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
@@ -123,7 +123,7 @@ public class TraitTypeCheckingExtension extends 
AbstractTypeCheckingExtension {
         System.arraycopy(argumentTypes, 0, newArgs, 0, newArgs.length);
         ClassNode inferredReturnType = inferTraitMethodReturnType(nextTrait, 
name, newArgs);
 
-        return Arrays.asList(makeDynamic(call, inferredReturnType));
+        return Collections.singletonList(makeDynamic(call, 
inferredReturnType));
     }
 
     private ClassNode inferTraitMethodReturnType(ClassNode nextTrait, String 
methodName, ClassNode[] paramTypes) {

Reply via email to