harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r772857 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang: Double.java Float.java
Date Fri, 08 May 2009 06:24:21 GMT
Author: egor
Date: Fri May  8 06:24:21 2009
New Revision: 772857

URL: http://svn.apache.org/viewvc?rev=772857&view=rev
Log:
Branching optimization for Float and Double compare.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java?rev=772857&r1=772856&r2=772857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java Fri May
 8 06:24:21 2009
@@ -365,11 +365,9 @@
         // Deal with +0.0 and -0.0
         long d1 = doubleToRawLongBits(double1);
         long d2 = doubleToRawLongBits(double2);
-
-        if (d1 == d2) {
-            return 0;
-        }
-        return (d1 < d2) ? -1 : 1;
+        // The below expression is equivalent to:
+        // (d1 == d2) ? 0 : (d1 < d2) ? -1 : 1
+        return (int) ((d1 >> 63) - (d2 >> 63));
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java?rev=772857&r1=772856&r2=772857&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Float.java Fri May
 8 06:24:21 2009
@@ -369,11 +369,10 @@
         // Deal with +0.0 and -0.0
         int f1 = floatToRawIntBits(float1);
         int f2 = floatToRawIntBits(float2);
-
-        if (f1 == f2) {
-            return 0;
-        }
-        return (f1 < f2) ? -1 : 1;
+        // The below expression is equivalent to:
+        // (f1 == f2) ? 0 : (f1 < f2) ? -1 : 1
+        // because f1 and f2 are either 0 or Integer.MIN_VALUE
+        return (f1 >> 31) - (f2 >> 31);
     }
 
     /**



Mime
View raw message