You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/12/01 00:19:02 UTC
groovy git commit: Minor refactoring
Repository: groovy
Updated Branches:
refs/heads/master e5d0d729f -> 2ffc1eadc
Minor refactoring
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2ffc1ead
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2ffc1ead
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2ffc1ead
Branch: refs/heads/master
Commit: 2ffc1eadce704e2b051e86c2c9ac631706da6c36
Parents: e5d0d72
Author: sunlan <su...@apache.org>
Authored: Fri Dec 1 08:18:56 2017 +0800
Committer: sunlan <su...@apache.org>
Committed: Fri Dec 1 08:18:56 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/2ffc1ead/src/main/groovy/lang/MetaClassImpl.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MetaClassImpl.java b/src/main/groovy/lang/MetaClassImpl.java
index af984c9..84b396c 100644
--- a/src/main/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/lang/MetaClassImpl.java
@@ -1643,19 +1643,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) {
@@ -1677,6 +1665,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
@@ -1698,19 +1703,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);