groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring: remove duplicated code
Date Wed, 07 Feb 2018 13:50:31 GMT
Repository: groovy
Updated Branches:
  refs/heads/master ffb33c594 -> 08d108220


Minor refactoring: remove duplicated code


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

Branch: refs/heads/master
Commit: 08d108220747260e4dd2c74a1aae515e44e30fd3
Parents: ffb33c5
Author: Daniel Sun <realbluesun@hotmail.com>
Authored: Wed Feb 7 21:50:27 2018 +0800
Committer: Daniel Sun <realbluesun@hotmail.com>
Committed: Wed Feb 7 21:50:27 2018 +0800

----------------------------------------------------------------------
 .../groovy/classgen/asm/BytecodeHelper.java     |  2 +-
 .../groovy/classgen/asm/OperandStack.java       | 34 +-------------------
 2 files changed, 2 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/08d10822/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java b/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
index 25fa258..af464f4 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/BytecodeHelper.java
@@ -207,7 +207,7 @@ public class BytecodeHelper implements Opcodes {
                 } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
{
                     mv.visitIntInsn(SIPUSH, value);
                 } else {
-                    mv.visitLdcInsn(Integer.valueOf(value));
+                    mv.visitLdcInsn(value);
                 }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/08d10822/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
index 9ba551e..f8a494c 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
@@ -66,10 +66,6 @@ import static org.objectweb.asm.Opcodes.I2L;
 import static org.objectweb.asm.Opcodes.I2S;
 import static org.objectweb.asm.Opcodes.ICONST_0;
 import static org.objectweb.asm.Opcodes.ICONST_1;
-import static org.objectweb.asm.Opcodes.ICONST_2;
-import static org.objectweb.asm.Opcodes.ICONST_3;
-import static org.objectweb.asm.Opcodes.ICONST_4;
-import static org.objectweb.asm.Opcodes.ICONST_5;
 import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
 import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
 import static org.objectweb.asm.Opcodes.L2D;
@@ -80,7 +76,6 @@ import static org.objectweb.asm.Opcodes.LCONST_1;
 import static org.objectweb.asm.Opcodes.NEW;
 import static org.objectweb.asm.Opcodes.POP;
 import static org.objectweb.asm.Opcodes.POP2;
-import static org.objectweb.asm.Opcodes.SIPUSH;
 import static org.objectweb.asm.Opcodes.SWAP;
 
 public class OperandStack {
@@ -535,34 +530,7 @@ public class OperandStack {
         boolean isChar = ClassHelper.char_TYPE.equals(type);
         if (isInt || isShort || isByte || isChar) {
             int val = isInt?(Integer)value:isShort?(Short)value:isChar?(Character)value:(Byte)value;
-            switch (val) {
-                case 0:
-                    mv.visitInsn(ICONST_0);
-                    break;
-                case 1:
-                    mv.visitInsn(ICONST_1);
-                    break;
-                case 2:
-                    mv.visitInsn(ICONST_2);
-                    break;
-                case 3:
-                    mv.visitInsn(ICONST_3);
-                    break;
-                case 4:
-                    mv.visitInsn(ICONST_4);
-                    break;
-                case 5:
-                    mv.visitInsn(ICONST_5);
-                    break;
-                default:
-                    if (val>=Byte.MIN_VALUE && val<=Byte.MAX_VALUE) {
-                        mv.visitIntInsn(BIPUSH, val);
-                    } else if (val>=Short.MIN_VALUE && val<=Short.MAX_VALUE)
{
-                        mv.visitIntInsn(SIPUSH, val);
-                    } else {
-                        mv.visitLdcInsn(value);
-                    }
-            }
+            BytecodeHelper.pushConstant(mv, val);
         } else if (ClassHelper.long_TYPE.equals(type)) {
             if ((Long)value==0L) {
                 mv.visitInsn(LCONST_0);


Mime
View raw message