Repository: groovy Updated Branches: refs/heads/master c800bb006 -> 3e167cc2f
Trivial refactoring: extract variable Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3e167cc2 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3e167cc2 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3e167cc2 Branch: refs/heads/master Commit: 3e167cc2f957a9e012546917df19b9d82e6cf207 Parents: c800bb0 Author: sunlan <[email protected]> Authored: Thu Jan 11 10:58:55 2018 +0800 Committer: sunlan <[email protected]> Committed: Thu Jan 11 10:58:55 2018 +0800 ---------------------------------------------------------------------- .../classgen/asm/sc/StaticInvocationWriter.java | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/3e167cc2/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java index c2978e9..d2b5bc7 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java @@ -417,16 +417,17 @@ public class StaticInvocationWriter extends InvocationWriter { AsmClassGenerator acg = controller.getAcg(); TypeChooser typeChooser = controller.getTypeChooser(); OperandStack operandStack = controller.getOperandStack(); - ClassNode lastArgType = !argumentList.isEmpty() ? - typeChooser.resolveType(argumentList.get(argumentList.size()-1), controller.getClassNode()):null; + int argumentListSize = argumentList.size(); + ClassNode lastArgType = argumentListSize > 0 ? + typeChooser.resolveType(argumentList.get(argumentListSize -1), controller.getClassNode()):null; if (lastParaType.isArray() - && ((argumentList.size() > para.length) - || ((argumentList.size() == (para.length - 1)) && !lastParaType.equals(lastArgType)) - || ((argumentList.size() == para.length && lastArgType!=null && !lastArgType.isArray()) + && ((argumentListSize > para.length) + || ((argumentListSize == (para.length - 1)) && !lastParaType.equals(lastArgType)) + || ((argumentListSize == para.length && lastArgType!=null && !lastArgType.isArray()) && (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(lastArgType,lastParaType.getComponentType()))) || ClassHelper.GSTRING_TYPE.equals(lastArgType) && ClassHelper.STRING_TYPE.equals(lastParaType.getComponentType())) ) { - int stackLen = operandStack.getStackLength() + argumentList.size(); + int stackLen = operandStack.getStackLength() + argumentListSize; MethodVisitor mv = controller.getMethodVisitor(); //mv = new org.objectweb.asm.util.TraceMethodVisitor(mv); controller.setMethodVisitor(mv); @@ -441,7 +442,7 @@ public class StaticInvocationWriter extends InvocationWriter { } // last parameters wrapped in an array List<Expression> lastParams = new LinkedList<Expression>(); - for (int i = para.length - 1; i < argumentList.size(); i++) { + for (int i = para.length - 1; i < argumentListSize; i++) { lastParams.add(argumentList.get(i)); } ArrayExpression array = new ArrayExpression( @@ -453,11 +454,11 @@ public class StaticInvocationWriter extends InvocationWriter { while (operandStack.getStackLength() < stackLen) { operandStack.push(ClassHelper.OBJECT_TYPE); } - if (argumentList.size() == para.length - 1) { + if (argumentListSize == para.length - 1) { operandStack.remove(1); } - } else if (argumentList.size() == para.length) { - for (int i = 0; i < argumentList.size(); i++) { + } else if (argumentListSize == para.length) { + for (int i = 0; i < argumentListSize; i++) { Expression expression = argumentList.get(i); expression.visit(acg); if (!isNullConstant(expression)) { @@ -471,7 +472,7 @@ public class StaticInvocationWriter extends InvocationWriter { for (int i = 0, j = 0; i < para.length; i++) { Parameter curParam = para[i]; ClassNode curParamType = curParam.getType(); - Expression curArg = j < argumentList.size() ? argumentList.get(j) : null; + Expression curArg = j < argumentListSize ? argumentList.get(j) : null; Expression initialExpression = curParam.getNodeMetaData(StaticTypesMarker.INITIAL_EXPRESSION); if (initialExpression == null && curParam.hasInitialExpression()) initialExpression = curParam.getInitialExpression();
