Browse Source

Double <-> Int64 conversion is much faster now.

Instead of using GetBytes and converting bytes to long, which
involves allocation and deallocation of small temporary array, the
simple cpu register load is in fact done now. This results in
a much faster operation.
Konrad M. Kruczynski 13 years ago
parent
commit
fdae58587b
1 changed files with 4 additions and 4 deletions
  1. 4 4
      mcs/class/corlib/System/BitConverter.cs

+ 4 - 4
mcs/class/corlib/System/BitConverter.cs

@@ -60,14 +60,14 @@ namespace System
 			return b [2] == 0xf0;
 		}
 
-		public static long DoubleToInt64Bits (double value)
+		public unsafe static long DoubleToInt64Bits (double value)
 		{
-			return ToInt64 (GetBytes (value), 0);
+			return *(long *) &value;
 		}
 
-		public static double Int64BitsToDouble (long value)
+		public unsafe static double Int64BitsToDouble (long value)
 		{
-			return ToDouble (GetBytes (value), 0);
+			return *(double *) &value;
 		}
 
 		internal static double InternalInt64BitsToDouble (long value)