Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit b6bde62

Browse files
cartermpKevinRansom
authored andcommitted
Optimize DateTime comparison/equality (dotnet#9224)
* Replace 'max' with DateTime.Compare in ComputeMaxTimeStamp * Generalize datetime in fsharp.core * baselines Co-authored-by: Kevin Ransom <[email protected]>
1 parent d6a50f4 commit b6bde62

File tree

3 files changed

+149
-121
lines changed

3 files changed

+149
-121
lines changed

src/fsharp/FSharp.Core/prim-types.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ namespace Microsoft.FSharp.Core
10451045
// gives reliable results on null values.
10461046
System.String.CompareOrdinal((# "" x : string #),(# "" y : string #))
10471047
when 'T : decimal = System.Decimal.Compare((# "" x:decimal #), (# "" y:decimal #))
1048+
when 'T : DateTime = System.DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #))
10481049

10491050

10501051
/// Generic comparison. Implements ER mode (where "0" is returned when NaNs are compared)
@@ -1123,6 +1124,7 @@ namespace Microsoft.FSharp.Core
11231124
// gives reliable results on null values.
11241125
System.String.CompareOrdinal((# "" x : string #),(# "" y : string #))
11251126
when 'T : decimal = System.Decimal.Compare((# "" x:decimal #), (# "" y:decimal #))
1127+
when 'T : DateTime = System.DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #))
11261128

11271129
/// Generic less-than with static optimizations for some well-known cases.
11281130
let inline GenericLessThanFast (x:'T) (y:'T) =
@@ -1142,6 +1144,7 @@ namespace Microsoft.FSharp.Core
11421144
when 'T : float32= (# "clt" x y : bool #)
11431145
when 'T : char = (# "clt" x y : bool #)
11441146
when 'T : decimal = System.Decimal.op_LessThan ((# "" x:decimal #), (# "" y:decimal #))
1147+
when 'T : DateTime = DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #)) < 0
11451148

11461149
/// Generic greater-than with static optimizations for some well-known cases.
11471150
let inline GenericGreaterThanFast (x:'T) (y:'T) =
@@ -1161,6 +1164,7 @@ namespace Microsoft.FSharp.Core
11611164
when 'T : float32 = (# "cgt" x y : bool #)
11621165
when 'T : char = (# "cgt" x y : bool #)
11631166
when 'T : decimal = System.Decimal.op_GreaterThan ((# "" x:decimal #), (# "" y:decimal #))
1167+
when 'T : DateTime = DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #)) > 0
11641168

11651169
/// Generic less-than-or-equal with static optimizations for some well-known cases.
11661170
let inline GenericLessOrEqualFast (x:'T) (y:'T) =
@@ -1180,6 +1184,7 @@ namespace Microsoft.FSharp.Core
11801184
when 'T : float32 = not (# "cgt.un" x y : bool #)
11811185
when 'T : char = not(# "cgt" x y : bool #)
11821186
when 'T : decimal = System.Decimal.op_LessThanOrEqual ((# "" x:decimal #), (# "" y:decimal #))
1187+
when 'T : DateTime = DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #)) <= 0
11831188

11841189
/// Generic greater-than-or-equal with static optimizations for some well-known cases.
11851190
let inline GenericGreaterOrEqualFast (x:'T) (y:'T) =
@@ -1199,6 +1204,8 @@ namespace Microsoft.FSharp.Core
11991204
when 'T : float32 = not (# "clt.un" x y : bool #)
12001205
when 'T : char = not (# "clt" x y : bool #)
12011206
when 'T : decimal = System.Decimal.op_GreaterThanOrEqual ((# "" x:decimal #), (# "" y:decimal #))
1207+
1208+
when 'T : DateTime = DateTime.Compare((# "" x : DateTime #), (# "" y : DateTime #)) >= 0
12021209

12031210

12041211
//-------------------------------------------------------------------------
@@ -1482,6 +1489,7 @@ namespace Microsoft.FSharp.Core
14821489
when 'T : char = (# "ceq" x y : bool #)
14831490
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
14841491
when 'T : decimal = System.Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #))
1492+
when 'T : DateTime = DateTime.Equals((# "" x : DateTime #), (# "" y : DateTime #))
14851493

14861494
/// Implements generic equality between two values, with PER semantics for NaN (so equality on two NaN values returns false)
14871495
//
@@ -1504,6 +1512,8 @@ namespace Microsoft.FSharp.Core
15041512
when 'T : unativeint = (# "ceq" x y : bool #)
15051513
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
15061514
when 'T : decimal = System.Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #))
1515+
when 'T : DateTime = DateTime.Equals((# "" x : DateTime #), (# "" y : DateTime #))
1516+
15071517

15081518
/// A compiler intrinsic generated during optimization of calls to GenericEqualityIntrinsic on tuple values.
15091519
//
@@ -1530,6 +1540,7 @@ namespace Microsoft.FSharp.Core
15301540
when 'T : unativeint = (# "ceq" x y : bool #)
15311541
when 'T : string = System.String.Equals((# "" x : string #),(# "" y : string #))
15321542
when 'T : decimal = System.Decimal.op_Equality((# "" x:decimal #), (# "" y:decimal #))
1543+
when 'T : DateTime = DateTime.Equals((# "" x : DateTime #), (# "" y : DateTime #))
15331544

15341545

15351546
let inline GenericInequalityFast (x:'T) (y:'T) = (not(GenericEqualityFast x y) : bool)

0 commit comments

Comments
 (0)