Speed optimization for round_int; removed a duplicate method in Cast.java

Patch by: cromwellian, me
Review by: me

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1472 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
index 712cc38..2ae869d 100644
--- a/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
+++ b/dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java
@@ -79,37 +79,36 @@
   }-*/;
 
   /**
-   * See JLS 5.1.3 for why we do a two-step cast. First we rount to int, then
+   * See JLS 5.1.3 for why we do a two-step cast. First we round to int, then
    * narrow to byte.
    */
   static byte round_byte(Object x) {
-    return narrow_byte(floatToInt(x));
+    return narrow_byte(round_int(x));
   }
 
   /**
-   * See JLS 5.1.3 for why we do a two-step cast. First we rount to int, then
+   * See JLS 5.1.3 for why we do a two-step cast. First we round to int, then
    * narrow to char.
    */
   static char round_char(Object x) {
-    return narrow_char(floatToInt(x));
+    return narrow_char(round_int(x));
   }
 
   /**
    * See JLS 5.1.3.
    */
   static native int round_int(Object x) /*-{
-    if (x > @java.lang.Integer::MAX_VALUE) return @java.lang.Integer::MAX_VALUE;
-    if (x < @java.lang.Integer::MIN_VALUE) return @java.lang.Integer::MIN_VALUE;
-    return x >= 0 ? Math.floor(x) : Math.ceil(x);
+    // TODO: reference java.lang.Integer::MAX_VALUE when we get clinits fixed
+    return ~~Math.max(Math.min(x, 2147483647), -2147483648);
   }-*/;
 
   /**
    * See JLS 5.1.3.
    */
   static native long round_long(Object x) /*-{
-    if (x > @java.lang.Long::MAX_VALUE) return @java.lang.Long::MAX_VALUE;
-    if (x < @java.lang.Long::MIN_VALUE) return @java.lang.Long::MIN_VALUE;
-    return x >= 0 ? Math.floor(x) : Math.ceil(x);
+    // TODO: reference java.lang.Long::MAX_VALUE when we get clinits fixed
+    x = Math.max(Math.min(x, 9223372036854775807), -9223372036854775808);
+    return (x >= 0) ? Math.floor(x) : Math.ceil(x);
   }-*/;
 
   /**
@@ -117,7 +116,7 @@
    * narrow to short.
    */
   static short round_short(Object x) {
-    return narrow_short(floatToInt(x));
+    return narrow_short(round_int(x));
   }
 
   /**
@@ -162,15 +161,6 @@
     return jso;
   }-*/;
 
-  /**
-   * See JLS 5.1.3.
-   */
-  private static native Object floatToInt(Object x) /*-{
-    if (x > @java.lang.Integer::MAX_VALUE) return @java.lang.Integer::MAX_VALUE;
-    if (x < @java.lang.Integer::MIN_VALUE) return @java.lang.Integer::MIN_VALUE;
-    return x >= 0 ? Math.floor(x) : Math.ceil(x);
-  }-*/;
-
 }
 
 // CHECKSTYLE_NAMING_ON