Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 3987626ac -> 5c4360725
Minor refactoring (cherry picked from commit 2ffc1ea) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5c436072 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5c436072 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5c436072 Branch: refs/heads/GROOVY_2_5_X Commit: 5c4360725bbf15264ff0dafe1330224395849c1a Parents: 3987626 Author: sunlan <[email protected]> Authored: Fri Dec 1 08:18:56 2017 +0800 Committer: sunlan <[email protected]> Committed: Fri Dec 1 08:19:52 2017 +0800 ---------------------------------------------------------------------- src/main/groovy/lang/MetaClassImpl.java | 45 ++++++++++++---------------- 1 file changed, 19 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/5c436072/src/main/groovy/lang/MetaClassImpl.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java index 55ffc4c..616b740 100644 --- a/src/main/groovy/lang/MetaClassImpl.java +++ b/src/main/groovy/lang/MetaClassImpl.java @@ -1580,19 +1580,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass { this.theClass.getName() + " do not match. Expected " + numberOfConstructors + " but got " + constructors.size()); } - if (arguments == null) arguments = EMPTY_ARGUMENTS; - Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); - MetaClassHelper.unwrap(arguments); - CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); - if (constructor == null) { - constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); - } - if (constructor == null) { - throw new GroovyRuntimeException( - "Could not find matching constructor for: " - + theClass.getName() - + "(" + InvokerHelper.toTypeString(arguments) + ")"); - } + CachedConstructor constructor = createCachedConstructor(arguments); List l = new ArrayList(constructors.toList()); Comparator comp = new Comparator() { public int compare(Object arg0, Object arg1) { @@ -1614,6 +1602,23 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass { return 0 | (found << 8); } + private CachedConstructor createCachedConstructor(Object[] arguments) { + if (arguments == null) arguments = EMPTY_ARGUMENTS; + Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); + MetaClassHelper.unwrap(arguments); + CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); + if (constructor == null) { + constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); + } + if (constructor == null) { + throw new GroovyRuntimeException( + "Could not find matching constructor for: " + + theClass.getName() + + "(" + InvokerHelper.toTypeString(arguments) + ")"); + } + return constructor; + } + /** * Constructor selection algorithm for Groovy 2.1.9+. * This selection algorithm was introduced as a workaround for GROOVY-6080. Instead of generating an index between @@ -1635,19 +1640,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass { * @since 2.1.9 */ private int selectConstructorAndTransformArguments1(Object[] arguments) { - if (arguments == null) arguments = EMPTY_ARGUMENTS; - Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); - MetaClassHelper.unwrap(arguments); - CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); - if (constructor == null) { - constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses); - } - if (constructor == null) { - throw new GroovyRuntimeException( - "Could not find matching constructor for: " - + theClass.getName() - + "(" + InvokerHelper.toTypeString(arguments) + ")"); - } + CachedConstructor constructor = createCachedConstructor(arguments); final String methodDescriptor = BytecodeHelper.getMethodDescriptor(Void.TYPE, constructor.getNativeParameterTypes()); // keeping 3 bits for additional information such as vargs return BytecodeHelper.hashCode(methodDescriptor);
