Repository: groovy Updated Branches: refs/heads/master 00b564ec1 -> ea515f428
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/ea515f42 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ea515f42 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ea515f42 Branch: refs/heads/master Commit: ea515f428f99b5a98a1eb7fb2837f8f84c803bd6 Parents: 00b564e Author: sunlan <[email protected]> Authored: Thu Nov 30 16:15:43 2017 +0800 Committer: sunlan <[email protected]> Committed: Thu Nov 30 16:15:43 2017 +0800 ---------------------------------------------------------------------- .../codehaus/groovy/classgen/asm/MopWriter.java | 6 +++--- .../codehaus/groovy/runtime/CurriedClosure.java | 21 ++++++++++---------- .../InheritConstructorsASTTransformation.java | 9 ++------- 3 files changed, 15 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/ea515f42/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 7231ca1..4f8f48c 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/ea515f42/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/ea515f42/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 5c6f3d0..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; @@ -126,12 +127,6 @@ public class InheritConstructorsASTTransformation extends AbstractASTTransformat } private static 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; + return MopWriter.equalParameterTypes(params, existingParams); } }
