Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
648b95f
Helper function for FastGenericEqualityComparerTable
manofstick Jun 5, 2018
413b9e5
Use the default equality comparer where applicable
manofstick Jun 5, 2018
64f65d6
Avoid calls to GenericEqualityObj for known types
manofstick Jun 5, 2018
354c7b2
Avoid boxing in the "standard" use of GenericEqualityWithComparerIntr…
manofstick Jun 6, 2018
0dcd0f9
Added method to avoid tail calls
manofstick Jun 6, 2018
189a7e9
Implemented hashing
manofstick Jun 6, 2018
8fc8fcd
Additional use of EqualityComparer.Default
manofstick Jun 6, 2018
e4be905
Consistent naming
manofstick Jun 6, 2018
67f3e9a
Fixed up by mix up my ERs with my PERs!
manofstick Jun 7, 2018
b6a2076
Apply De Morgan's law to make it a bit cleaner
manofstick Jun 7, 2018
984ee58
Argh, got the PER and ER mixed up even when I tried to fix. Now good …
manofstick Jun 8, 2018
9778b98
Removed custom delegates by using System.Func
manofstick Jun 8, 2018
f66d842
Disallow optimization on Nullable types
manofstick Jun 8, 2018
d53a1f3
More inclusive check for canUseDefaultEqualityComparer
manofstick Jun 9, 2018
325707f
Updated il output files
manofstick Jun 9, 2018
070cf6a
Removed IERorPER by splitting calling class into 2, and added helper …
manofstick Jun 11, 2018
70290f1
Changed it all to used EqualityComparer derived classes and restored …
manofstick Jun 13, 2018
4771226
Removed comparers that matched EqualityComparer<>.Default and code re…
manofstick Jun 14, 2018
c864428
Added additional types where EqualityComparer.Default can be used
manofstick Jun 16, 2018
07d96ee
Save unnecessary type checks when more information is known
manofstick Jun 16, 2018
edc211e
Removed now unused objects, and other minor cleanup
manofstick Jun 18, 2018
4a36c1e
Modified Optimizer to manually inline GenericEqualityIntrinsic and fr…
manofstick Jun 23, 2018
f87500c
Fixed SurfaceArea
manofstick Jun 23, 2018
6fb8c31
Ensure FSharp.Core has the optimization functions (and added comments)
manofstick Jun 23, 2018
a734563
Remove IL bloat from this PR as per https://github.com/Microsoft/visu…
manofstick Jun 25, 2018
71bb238
Remove null checks for IStructuralEquality Value Types
manofstick Jun 26, 2018
d51ab1d
Consolidated Type Specific Array Equality functions
manofstick Jun 27, 2018
0390e93
Fix compiler call via FSharpFunc.Invoke rather than direct
manofstick Jun 27, 2018
9ea9790
Replaced duplicated GetHashCode code with inline function
manofstick Jun 28, 2018
03092bd
Common array EqualityComparers (for types that previously had special…
manofstick Jun 28, 2018
224f20d
Fix regression in regards to hash code on fast-path covariant arrays …
manofstick Jul 11, 2018
84ed1eb
Similar treatment within prim-types for Comparer as #5112 was for Equ…
manofstick Jul 1, 2018
cd855bb
Moved throwing exceptions closer
manofstick Jul 2, 2018
87a2c6a
Added comparison usage, so could remove exception catching logic when…
manofstick Jul 2, 2018
0d56890
Consolidated functions
manofstick Jul 3, 2018
6fcde31
Consolidated ArrayComparisons and addressed issue #5263
manofstick Jul 3, 2018
b9433c2
Fixed bug introduced in #5278 where an unstable sort could be used wh…
manofstick Jul 18, 2018
bae4ab8
Removed now unnecessary optimization from stableSortWithKeysAndComparer
manofstick Jul 19, 2018
8c891a1
Moved isRecordType down to prim-types.fs (internal only)
manofstick Jul 8, 2018
39b275e
Moved enough of reflect.fs to get Record fields
manofstick Jul 8, 2018
395edf6
Moved reflection functions for Union types into prim-types.fs
manofstick Jul 9, 2018
d3a6f23
Removed methods from prim-types.fsi that are now just used internally
manofstick Jul 9, 2018
80d6547
Used the reflection functions to handle records and unions
manofstick Jul 9, 2018
fbecaf2
Added check for fsharp value types
manofstick Jul 9, 2018
66be88f
Fixed struct check where a [<DefaultValue>] field is used.
manofstick Jul 10, 2018
fd6d783
Minor shift in logic order for less comparisons
manofstick Jul 11, 2018
f117985
Removed MapOne case for performance.
manofstick Jul 19, 2018
c0e872d
Converted Map.Count from O(n) to O(1)
manofstick Jul 20, 2018
dbc11d9
inlined mk/mkLeaf
manofstick Jul 21, 2018
cfb0201
optimize ofSeq, ofList, ofArray via a temporary sorted ResizeArray an…
manofstick Jul 21, 2018
0e52fde
Split rebalance so as to inline decision logic
manofstick Jul 24, 2018
b18c16c
Removed MapEmpty
manofstick Jul 26, 2018
d20d48f
manual selective inlining of rebalance in add
manofstick Jul 26, 2018
cb0ac57
Only access members when necessary - measurable performance diff for …
manofstick Jul 28, 2018
ec978d1
Consolidated find functionality
manofstick Jul 28, 2018
5e1ff83
Labelled MapNode fields
manofstick Jul 28, 2018
bede577
Revamped enumeration to create less garbage. Faster on 64-bit, slower…
manofstick Jul 29, 2018
3b83856
Added Checked logic to ensure size constraint isn't violated
manofstick Jul 29, 2018
4ab22c9
findImpl use helper functions to clean up
manofstick Jul 29, 2018
a3d49c7
Made the non-(to|of)(Seq|List|Array) Map changes to the TaggedCollect…
manofstick Jul 29, 2018
4b0fc38
Removed SetOne
manofstick Jul 30, 2018
e91c10e
Converted Set's height to size
manofstick Jul 30, 2018
074d902
Cut SetTree down to just SetNode
manofstick Jul 31, 2018
df2e8dd
rebalance split and add from Map
manofstick Aug 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/fsharp/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,12 @@ module internal Array =

open System

let inline fastComparerForArraySort<'t when 't : comparison> () =
LanguagePrimitives.FastGenericComparerCanBeNull<'t>
let inline getInternalComparer<'t when 't : comparison> () =
// Previously a "comparer" was returned the could be null, which was for optimized Array.Sort
// but we now mainly return Comparer.Default (and FastGenericComparerInternal more so)
// which is also optimized in Array.Sort
// ** this comment can be destroyed sometime in the future, it is just as a breadcrumb for review **
LanguagePrimitives.FastGenericComparerInternal<'t>

// The input parameter should be checked by callers if necessary
let inline zeroCreateUnchecked (count:int) =
Expand Down Expand Up @@ -1089,26 +1093,26 @@ module internal Array =
let keys = zeroCreateUnchecked array.Length
for i = 0 to array.Length - 1 do
keys.[i] <- projection array.[i]
Array.Sort<_,_>(keys, array, fastComparerForArraySort())
Array.Sort<_,_>(keys, array, getInternalComparer())

let unstableSortInPlace (array : array<'T>) =
let len = array.Length
if len < 2 then ()
else Array.Sort<_>(array, fastComparerForArraySort())
else Array.Sort<_>(array, getInternalComparer())

let stableSortWithKeysAndComparer (cFast:IComparer<'Key>) (c:IComparer<'Key>) (array:array<'T>) (keys:array<'Key>) =
let stableSortWithKeysAndComparer (c:IComparer<'Key>) (array:array<'T>) (keys:array<'Key>) =
// 'places' is an array or integers storing the permutation performed by the sort
let places = zeroCreateUnchecked array.Length
for i = 0 to array.Length - 1 do
places.[i] <- i
System.Array.Sort<_,_>(keys, places, cFast)
System.Array.Sort<_,_>(keys, places, c)
// 'array2' is a copy of the original values
let array2 = (array.Clone() :?> array<'T>)

// Walk through any chunks where the keys are equal
let mutable i = 0
let len = array.Length
let intCompare = fastComparerForArraySort<int>()
let intCompare = getInternalComparer<int>()

while i < len do
let mutable j = i
Expand All @@ -1123,9 +1127,8 @@ module internal Array =
i <- j

let stableSortWithKeys (array:array<'T>) (keys:array<'Key>) =
let cFast = fastComparerForArraySort()
let c = LanguagePrimitives.FastGenericComparer<'Key>
stableSortWithKeysAndComparer cFast c array keys
let c = getInternalComparer()
stableSortWithKeysAndComparer c array keys

let stableSortInPlaceBy (projection: 'T -> 'U) (array : array<'T>) =
let len = array.Length
Expand All @@ -1141,13 +1144,11 @@ module internal Array =
let len = array.Length
if len < 2 then ()
else
let cFast = LanguagePrimitives.FastGenericComparerCanBeNull<'T>
match cFast with
| null ->
if LanguagePrimitives.EquivalentForStableAndUnstableSort<'T> then
// An optimization for the cases where the keys and values coincide and do not have identity, e.g. are integers
// In this case an unstable sort is just as good as a stable sort (and faster)
Array.Sort<_,_>(array, null)
| _ ->
else
// 'keys' is an array storing the projected keys
let keys = (array.Clone() :?> array<'T>)
stableSortWithKeys array keys
Expand All @@ -1158,7 +1159,7 @@ module internal Array =
let keys = (array.Clone() :?> array<'T>)
let comparer = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(comparer)
let c = { new IComparer<'T> with member __.Compare(x,y) = comparer.Invoke(x,y) }
stableSortWithKeysAndComparer c c array keys
stableSortWithKeysAndComparer c array keys

let inline subUnchecked startIndex count (array : 'T[]) =
let res = zeroCreateUnchecked count : 'T[]
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/FSharp.Core/local.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ module internal Array =
val stableSortInPlaceWith: comparer:('T -> 'T -> int) -> array:'T[] -> unit

val stableSortInPlace: array:'T[] -> unit when 'T : comparison

val stableSortWithKeysAndComparer : System.Collections.Generic.IComparer<'Key> -> array<'T> -> array<'Key> -> unit when 'Key : comparison
Loading