You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by eg...@apache.org on 2009/05/08 08:52:38 UTC
svn commit: r772865 - in
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java:
lang/Double.java util/Arrays.java
Author: egor
Date: Fri May 8 06:52:38 2009
New Revision: 772865
URL: http://svn.apache.org/viewvc?rev=772865&view=rev
Log:
hopefully faster and definitely more specialized Arrays.lessThan() for float and double
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Double.java
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.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=772865&r1=772864&r2=772865&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:52:38 2009
@@ -352,7 +352,7 @@
return 0;
}
- // NaNs are equal to other NaNs and larger than any other float
+ // NaNs are equal to other NaNs and larger than any other double
if (isNaN(double1)) {
if (isNaN(double2)) {
return 0;
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?rev=772865&r1=772864&r2=772865&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java Fri May 8 06:52:38 2009
@@ -1558,11 +1558,52 @@
}
private static boolean lessThan(double double1, double double2) {
- return Double.compare(double1, double2) < 0;
+ // A slightly specialized version of
+ // Double.compare(double1, double2) < 0.
+
+ // Non-zero and non-NaN checking.
+ if (double1 < double2) {
+ return true;
+ }
+ if (double1 >= double2 && (0.0d != double1 || 0.0d != double2)) {
+ return false;
+ }
+
+ // NaNs are equal to other NaNs and larger than any other double.
+ if (Double.isNaN(double1)) {
+ return false;
+ } else if (Double.isNaN(double2)) {
+ return true;
+ }
+
+ // Deal with +0.0 and -0.0.
+ long d1 = Double.doubleToRawLongBits(double1);
+ long d2 = Double.doubleToRawLongBits(double2);
+ return d1 < d2;
}
private static boolean lessThan(float float1, float float2) {
- return Float.compare(float1, float2) < 0;
+ // A slightly specialized version of Float.compare(float1, float2) < 0.
+
+ // Non-zero and non-NaN checking.
+ if (float1 < float2) {
+ return true;
+ }
+ if (float1 >= float2 && (0.0f != float1 || 0.0f != float2)) {
+ return false;
+ }
+
+ // NaNs are equal to other NaNs and larger than any other float
+ if (Float.isNaN(float1)) {
+ return false;
+ } else if (Float.isNaN(float2)) {
+ return true;
+ }
+
+ // Deal with +0.0 and -0.0
+ int f1 = Float.floatToRawIntBits(float1);
+ int f2 = Float.floatToRawIntBits(float2);
+ return f1 < f2;
}
private static int med3(byte[] array, int a, int b, int c) {