groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/4] groovy git commit: Minor refactoring: remove duplicated code of `StaticTypesBinaryExpressionMultiTypeDispatcher`
Date Wed, 07 Feb 2018 15:15:01 GMT
Minor refactoring: remove duplicated code of `StaticTypesBinaryExpressionMultiTypeDispatcher`

(cherry picked from commit ea81620)

(cherry picked from commit fb2a021)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 63e7d90d472d5b18c1301616fb2c9c7144ff9b94
Parents: ed6e5a1
Author: Daniel Sun <realbluesun@hotmail.com>
Authored: Wed Feb 7 22:33:18 2018 +0800
Committer: Daniel Sun <realbluesun@hotmail.com>
Committed: Wed Feb 7 23:03:41 2018 +0800

----------------------------------------------------------------------
 ...ypesBinaryExpressionMultiTypeDispatcher.java | 42 +++++++-------------
 1 file changed, 15 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/63e7d90d/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
index 58d9562..2c4ba0b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
@@ -109,41 +109,29 @@ public class StaticTypesBinaryExpressionMultiTypeDispatcher extends
BinaryExpres
         ClassNode top = operandStack.getTopOperand();
         if (ClassHelper.isPrimitiveType(top) && (ClassHelper.isNumberType(top)||char_TYPE.equals(top)))
{
             MethodVisitor mv = controller.getMethodVisitor();
-            if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
-                mv.visitInsn(ICONST_1);
-            } else if (long_TYPE.equals(top)) {
-                mv.visitInsn(LCONST_1);
-            } else if (float_TYPE.equals(top)) {
-                mv.visitInsn(FCONST_1);
-            } else if (double_TYPE.equals(top)) {
-                mv.visitInsn(DCONST_1);
-            }
+            visitInsnByType(top, mv, ICONST_1, LCONST_1, FCONST_1, DCONST_1);
             if ("next".equals(method)) {
-                if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
-                    mv.visitInsn(IADD);
-                } else if (long_TYPE.equals(top)) {
-                    mv.visitInsn(LADD);
-                } else if (float_TYPE.equals(top)) {
-                    mv.visitInsn(FADD);
-                } else if (double_TYPE.equals(top)) {
-                    mv.visitInsn(DADD);
-                }
+                visitInsnByType(top, mv, IADD, LADD, FADD, DADD);
             } else {
-                if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
-                    mv.visitInsn(ISUB);
-                } else if (long_TYPE.equals(top)) {
-                    mv.visitInsn(LSUB);
-                } else if (float_TYPE.equals(top)) {
-                    mv.visitInsn(FSUB);
-                } else if (double_TYPE.equals(top)) {
-                    mv.visitInsn(DSUB);
-                }
+                visitInsnByType(top, mv, ISUB, LSUB, FSUB, DSUB);
             }
             return;
         }
         super.writePostOrPrefixMethod(op, method, expression, orig);
     }
 
+    private static void visitInsnByType(ClassNode top, MethodVisitor mv, int iInsn, int lInsn,
int fInsn, int dInsn) {
+        if (WideningCategories.isIntCategory(top) || char_TYPE.equals(top)) {
+            mv.visitInsn(iInsn);
+        } else if (long_TYPE.equals(top)) {
+            mv.visitInsn(lInsn);
+        } else if (float_TYPE.equals(top)) {
+            mv.visitInsn(fInsn);
+        } else if (double_TYPE.equals(top)) {
+            mv.visitInsn(dInsn);
+        }
+    }
+
     @Override
     public void evaluateEqual(final BinaryExpression expression, final boolean defineVariable)
{
         if (!defineVariable) {


Mime
View raw message