groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Remove unnecessary boxing and unboxing
Date Thu, 05 Jul 2018 06:30:58 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 2934d3c73 -> ccfd177d8


Remove unnecessary boxing and unboxing


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

Branch: refs/heads/master
Commit: ccfd177d84a626964fbadb4f359c8fabfad9e0b0
Parents: 2934d3c
Author: sunlan <sunlan@apache.org>
Authored: Thu Jul 5 14:29:56 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Jul 5 14:29:56 2018 +0800

----------------------------------------------------------------------
 .../typehandling/DefaultTypeTransformation.java | 38 ++++++++++----------
 .../runtime/typehandling/FloatingPointMath.java | 16 ++++-----
 .../runtime/typehandling/IntegerMath.java       | 30 ++++++++--------
 .../groovy/runtime/typehandling/LongMath.java   | 32 ++++++++---------
 4 files changed, 58 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ccfd177d/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index f13317e..14cbecc 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -111,37 +111,37 @@ public class DefaultTypeTransformation {
 
     @Deprecated
     public static Object box(byte value) {
-        return Byte.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(char value) {
-        return Character.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(short value) {
-        return Short.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(int value) {
-        return Integer.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(long value) {
-        return Long.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(float value) {
-        return Float.valueOf(value);
+        return value;
     }
 
     @Deprecated
     public static Object box(double value) {
-        return Double.valueOf(value);
+        return value;
     }
 
     public static Number castToNumber(Object object) {
@@ -153,12 +153,12 @@ public class DefaultTypeTransformation {
         if (object instanceof Number)
             return (Number) object;
         if (object instanceof Character) {
-            return Integer.valueOf(((Character) object).charValue());
+            return (int) (Character) object;
         }
         if (object instanceof GString) {
             String c = ((GString) object).toString();
             if (c.length() == 1) {
-                return Integer.valueOf(c.charAt(0));
+                return (int) c.charAt(0);
             } else {
                 throw new GroovyCastException(c, type);
             }
@@ -166,7 +166,7 @@ public class DefaultTypeTransformation {
         if (object instanceof String) {
             String c = (String) object;
             if (c.length() == 1) {
-                return Integer.valueOf(c.charAt(0));
+                return (int) c.charAt(0);
             } else {
                 throw new GroovyCastException(c, type);
             }
@@ -189,7 +189,7 @@ public class DefaultTypeTransformation {
 
         // equality check is enough and faster than instanceof check, no need to check superclasses
since Boolean is final
         if (object.getClass() == Boolean.class) {
-            return ((Boolean) object).booleanValue();
+            return (Boolean) object;
         }
 
         // if the object is not null and no Boolean, try to call an asBoolean() method on
the object
@@ -199,7 +199,7 @@ public class DefaultTypeTransformation {
     @Deprecated
     public static char castToChar(Object object) {
         if (object instanceof Character) {
-            return ((Character) object).charValue();
+            return (Character) object;
         } else if (object instanceof Number) {
             Number value = (Number) object;
             return (char) value.intValue();
@@ -344,10 +344,10 @@ public class DefaultTypeTransformation {
         } else if (type == float.class) {
             return floatUnbox(object);
         } else if (type == double.class) {
-            Double answer = new Double(doubleUnbox(object));
+            Double answer = doubleUnbox(object);
             //throw a runtime exception if conversion would be out-of-range for the type.
-            if (!(object instanceof Double) && (answer.doubleValue() == Double.NEGATIVE_INFINITY
-                    || answer.doubleValue() == Double.POSITIVE_INFINITY)) {
+            if (!(object instanceof Double) && (answer == Double.NEGATIVE_INFINITY
+                    || answer == Double.POSITIVE_INFINITY)) {
                 throw new GroovyRuntimeException("Automatic coercion of " + object.getClass().getName()
                         + " value " + object + " to double failed.  Value is out of range.");
             }
@@ -648,7 +648,7 @@ public class DefaultTypeTransformation {
             }
             return false;
         }
-        return ((Boolean) InvokerHelper.invokeMethod(left, "equals", right)).booleanValue();
+        return (Boolean) InvokerHelper.invokeMethod(left, "equals", right);
     }
 
     public static boolean compareArrayEqual(Object left, Object right) {
@@ -714,7 +714,7 @@ public class DefaultTypeTransformation {
             ans = new boolean[ia.length];
             for (int i = 0; i < ia.length; i++) {
                 if (ia[i] == null) continue;
-                ans[i] = ((Boolean) ia[i]).booleanValue();
+                ans[i] = (Boolean) ia[i];
             }
         }
         return ans;
@@ -770,7 +770,7 @@ public class DefaultTypeTransformation {
                 if (ia[i] == null) {
                     continue;
                 }
-                ans[i] = ((Character) ia[i]).charValue();
+                ans[i] = (Character) ia[i];
             }
         }
         return ans;
@@ -872,7 +872,7 @@ public class DefaultTypeTransformation {
         if (value instanceof String) {
             String s = (String) value;
             if (s.length() != 1) throw new IllegalArgumentException("String of length 1 expected
but got a bigger one");
-            return Character.valueOf(s.charAt(0));
+            return s.charAt(0);
         } else {
             return ((Character) value);
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/ccfd177d/src/main/java/org/codehaus/groovy/runtime/typehandling/FloatingPointMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/FloatingPointMath.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/FloatingPointMath.java
index 53baa49..6bed405 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/FloatingPointMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/FloatingPointMath.java
@@ -30,23 +30,23 @@ public final class FloatingPointMath extends NumberMath {
     private FloatingPointMath() {}
                 
     protected Number absImpl(Number number) {
-        return new Double(Math.abs(number.doubleValue()));
+        return Math.abs(number.doubleValue());
     }
     
     public Number addImpl(Number left, Number right) {
-        return new Double(left.doubleValue() + right.doubleValue());
+        return left.doubleValue() + right.doubleValue();
     }
 
     public Number subtractImpl(Number left, Number right) {
-        return new Double(left.doubleValue() - right.doubleValue());
+        return left.doubleValue() - right.doubleValue();
     }
 
     public Number multiplyImpl(Number left, Number right) {
-        return new Double(left.doubleValue() * right.doubleValue());
+        return left.doubleValue() * right.doubleValue();
     }
 
     public Number divideImpl(Number left, Number right) {
-        return new Double(left.doubleValue() / right.doubleValue());
+        return left.doubleValue() / right.doubleValue();
     }
 
     public int compareToImpl(Number left, Number right) {
@@ -54,14 +54,14 @@ public final class FloatingPointMath extends NumberMath {
     }
     
     protected Number modImpl(Number left, Number right) {
-        return new Double(left.doubleValue() % right.doubleValue());
+        return left.doubleValue() % right.doubleValue();
     }
     
     protected Number unaryMinusImpl(Number left) {
-        return new Double(-left.doubleValue());
+        return -left.doubleValue();
     }
 
     protected Number unaryPlusImpl(Number left) {
-        return new Double(left.doubleValue());
+        return left.doubleValue();
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/ccfd177d/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
index 3792c3e..7fbc6aa 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
@@ -30,19 +30,19 @@ public final class IntegerMath extends NumberMath {
     private IntegerMath() {}
                     
     protected Number absImpl(Number number) {
-        return Integer.valueOf(Math.abs(number.intValue()));
+        return Math.abs(number.intValue());
     }
     
     public Number addImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() + right.intValue());
+        return left.intValue() + right.intValue();
     }
 
     public Number subtractImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() - right.intValue());
+        return left.intValue() - right.intValue();
     }
 
     public Number multiplyImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() * right.intValue());
+        return left.intValue() * right.intValue();
     }
 
     public Number divideImpl(Number left, Number right) {
@@ -56,46 +56,46 @@ public final class IntegerMath extends NumberMath {
     }
 
     protected Number orImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() | right.intValue());
+        return left.intValue() | right.intValue();
     }
 
     protected Number andImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() & right.intValue());
+        return left.intValue() & right.intValue();
     }
 
     protected Number xorImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() ^ right.intValue());
+        return left.intValue() ^ right.intValue();
     }
 
     protected Number intdivImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() / right.intValue());
+        return left.intValue() / right.intValue();
     }
     
     protected Number modImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() % right.intValue());
+        return left.intValue() % right.intValue();
     }
 
     protected Number unaryMinusImpl(Number left) {
-        return Integer.valueOf(-left.intValue());
+        return -left.intValue();
     }
 
     protected Number unaryPlusImpl(Number left) {
-        return Integer.valueOf(left.intValue());
+        return left.intValue();
     }
 
     protected Number bitwiseNegateImpl(Number left) {
-        return Integer.valueOf(~left.intValue());
+        return ~left.intValue();
     }
 
     protected Number leftShiftImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() << right.intValue());
+        return left.intValue() << right.intValue();
     }
 
     protected Number rightShiftImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() >> right.intValue());
+        return left.intValue() >> right.intValue();
     }
 
     protected Number rightShiftUnsignedImpl(Number left, Number right) {
-        return Integer.valueOf(left.intValue() >>> right.intValue());
+        return left.intValue() >>> right.intValue();
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/ccfd177d/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
index 8a8e6e0..e7f2d6e 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
@@ -30,19 +30,19 @@ public final class LongMath extends NumberMath {
     private LongMath() {}
                     
     protected Number absImpl(Number number) {
-        return Long.valueOf(Math.abs(number.longValue()));
+        return Math.abs(number.longValue());
     }
     
     public Number addImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() + right.longValue());
+        return left.longValue() + right.longValue();
     }
 
     public Number subtractImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() - right.longValue());
+        return left.longValue() - right.longValue();
     }
 
     public Number multiplyImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() * right.longValue());
+        return left.longValue() * right.longValue();
     }
 
     public Number divideImpl(Number left, Number right) {
@@ -56,50 +56,50 @@ public final class LongMath extends NumberMath {
     }
 
     protected Number intdivImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() / right.longValue());
+        return left.longValue() / right.longValue();
     }
     
     protected Number modImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() % right.longValue());
+        return left.longValue() % right.longValue();
     }
     
     protected Number unaryMinusImpl(Number left) {
-        return Long.valueOf(-left.longValue());
+        return -left.longValue();
     }
 
     protected Number unaryPlusImpl(Number left) {
-        return Long.valueOf(left.longValue());
+        return left.longValue();
     }
 
     protected Number bitwiseNegateImpl(Number left) {
-        return Long.valueOf(~left.longValue());
+        return ~left.longValue();
     }
     
     protected Number orImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() | right.longValue());
+        return left.longValue() | right.longValue();
     }
 
     protected Number andImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() & right.longValue());
+        return left.longValue() & right.longValue();
     }
     
     protected Number xorImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() ^ right.longValue());
+        return left.longValue() ^ right.longValue();
     }
     
     protected Number leftShiftImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() << right.longValue());
+        return left.longValue() << right.longValue();
     }
 
     protected Number rightShiftImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() >> right.longValue());
+        return left.longValue() >> right.longValue();
     }
 
     protected Number rightShiftUnsignedImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() >>> right.longValue());
+        return left.longValue() >>> right.longValue();
     }
 
     protected Number bitAndImpl(Number left, Number right) {
-        return Long.valueOf(left.longValue() & right.longValue());
+        return left.longValue() & right.longValue();
     }
 }


Mime
View raw message