Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 2d6b4bc02 -> 913ad1ef4


Minor refactoring

(cherry picked from commit ea515f4)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 913ad1ef49a615756fc2e43a384fb8e06f273159
Parents: 2d6b4bc
Author: sunlan <[email protected]>
Authored: Thu Nov 30 16:15:43 2017 +0800
Committer: sunlan <[email protected]>
Committed: Thu Nov 30 16:29:09 2017 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/classgen/asm/MopWriter.java |  6 +++---
 .../codehaus/groovy/runtime/CurriedClosure.java | 21 ++++++++++----------
 .../InheritConstructorsASTTransformation.java   | 13 ++++--------
 3 files changed, 17 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/913ad1ef/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java 
b/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
index 5ca2c41..b32ef4d 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/MopWriter.java
@@ -212,9 +212,9 @@ public class MopWriter {
         }
     }
 
-    private static boolean equalParameterTypes(Parameter[] p1, Parameter[] p2) 
{
-        if (p1.length!=p2.length) return false;
-        for (int i=0; i<p1.length; i++) {
+    public static boolean equalParameterTypes(Parameter[] p1, Parameter[] p2) {
+        if (p1.length != p2.length) return false;
+        for (int i = 0; i < p1.length; i++) {
             if (!p1[i].getType().equals(p2[i].getType())) return false;
         }
         return true;

http://git-wip-us.apache.org/repos/asf/groovy/blob/913ad1ef/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/CurriedClosure.java 
b/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
index 22a83cb..8700886 100644
--- a/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
+++ b/src/main/org/codehaus/groovy/runtime/CurriedClosure.java
@@ -106,24 +106,23 @@ public final class CurriedClosure<V> extends Closure<V> {
                 throw new IllegalArgumentException("When currying expected 
index range between " +
                         (-arguments.length - curriedParams.length) + ".." + 
(arguments.length + curriedParams.length) + " but found " + index);
             }
-            final Object newCurriedParams[] = new Object[curriedParams.length 
+ arguments.length];
-            System.arraycopy(arguments, 0, newCurriedParams, 0, 
normalizedIndex);
-            System.arraycopy(curriedParams, 0, newCurriedParams, 
normalizedIndex, curriedParams.length);
-            if (arguments.length - normalizedIndex > 0)
-                System.arraycopy(arguments, normalizedIndex, newCurriedParams, 
curriedParams.length + normalizedIndex, arguments.length - normalizedIndex);
-            return newCurriedParams;
+            return createNewCurriedParams(normalizedIndex, arguments);
         }
         if (curriedParams.length + arguments.length < minParamsExpected) {
             throw new IllegalArgumentException("When currying expected at 
least " + index + " argument(s) to be supplied before known curried arguments 
but found " + arguments.length);
         }
-        final Object newCurriedParams[] = new Object[curriedParams.length + 
arguments.length];
         int newIndex = Math.min(index, curriedParams.length + arguments.length 
- 1);
         // rcurried arguments are done lazily to allow normal method selection 
between overloaded alternatives
         newIndex = Math.min(newIndex, arguments.length);
-        System.arraycopy(arguments, 0, newCurriedParams, 0, newIndex);
-        System.arraycopy(curriedParams, 0, newCurriedParams, newIndex, 
curriedParams.length);
-        if (arguments.length - newIndex > 0)
-            System.arraycopy(arguments, newIndex, newCurriedParams, 
curriedParams.length + newIndex, arguments.length - newIndex);
+        return createNewCurriedParams(newIndex, arguments);
+    }
+
+    private Object[] createNewCurriedParams(int normalizedIndex, Object[] 
arguments) {
+        Object[] newCurriedParams = new Object[curriedParams.length + 
arguments.length];
+        System.arraycopy(arguments, 0, newCurriedParams, 0, normalizedIndex);
+        System.arraycopy(curriedParams, 0, newCurriedParams, normalizedIndex, 
curriedParams.length);
+        if (arguments.length - normalizedIndex > 0)
+            System.arraycopy(arguments, normalizedIndex, newCurriedParams, 
curriedParams.length + normalizedIndex, arguments.length - normalizedIndex);
         return newCurriedParams;
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/913ad1ef/src/main/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
 
b/src/main/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
index b4d89cb..f7db6e4 100644
--- 
a/src/main/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
+++ 
b/src/main/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
@@ -26,6 +26,7 @@ import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.ConstructorNode;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.classgen.asm.MopWriter;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.control.SourceUnit;
 
@@ -116,7 +117,7 @@ public class InheritConstructorsASTTransformation extends 
AbstractASTTransformat
         return theArgs;
     }
 
-    private boolean isExisting(ClassNode classNode, Parameter[] params) {
+    private static boolean isExisting(ClassNode classNode, Parameter[] params) 
{
         for (ConstructorNode consNode : classNode.getDeclaredConstructors()) {
             if (matchingTypes(params, consNode.getParameters())) {
                 return true;
@@ -125,13 +126,7 @@ public class InheritConstructorsASTTransformation extends 
AbstractASTTransformat
         return false;
     }
 
-    private boolean matchingTypes(Parameter[] params, Parameter[] 
existingParams) {
-        if (params.length != existingParams.length) return false;
-        for (int i = 0; i < params.length; i++) {
-            if (!params[i].getType().equals(existingParams[i].getType())) {
-                return false;
-            }
-        }
-        return true;
+    private static boolean matchingTypes(Parameter[] params, Parameter[] 
existingParams) {
+        return MopWriter.equalParameterTypes(params, existingParams);
     }
 }

Reply via email to