Skip to content

Commit be5cb58

Browse files
forkiKevinRansom
authored andcommitted
Empty shortcuts (#5370)
* Empty shortcuts * Empty shortcuts * Empty shortcuts
1 parent 5410276 commit be5cb58

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/fsharp/FSharp.Core/array.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ namespace Microsoft.FSharp.Collections
163163
Microsoft.FSharp.Primitives.Basics.Array.subUnchecked 0 count array
164164

165165
let inline countByImpl (comparer:IEqualityComparer<'SafeKey>) (projection:'T->'SafeKey) (getKey:'SafeKey->'Key) (array:'T[]) =
166+
let length = array.Length
167+
if length = 0 then Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked 0 else
168+
166169
let dict = Dictionary comparer
167170

168171
// Build the groupings
@@ -279,6 +282,9 @@ namespace Microsoft.FSharp.Collections
279282
[<CompiledName("DistinctBy")>]
280283
let distinctBy projection (array:'T[]) =
281284
checkNonNull "array" array
285+
let length = array.Length
286+
if length = 0 then Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked 0 else
287+
282288
let temp = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked array.Length
283289
let mutable i = 0
284290
let hashSet = HashSet<_>(HashIdentity.Structural<_>)

src/fsharp/FSharp.Core/list.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ namespace Microsoft.FSharp.Collections
4848
let concat lists = Microsoft.FSharp.Primitives.Basics.List.concat lists
4949

5050
let inline countByImpl (comparer:IEqualityComparer<'SafeKey>) (projection:'T->'SafeKey) (getKey:'SafeKey->'Key) (list:'T list) =
51+
match list with
52+
| [] -> []
53+
| _ ->
54+
5155
let dict = Dictionary comparer
5256
let rec loop srcList =
5357
match srcList with

src/fsharp/FSharp.Core/seq.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ namespace Microsoft.FSharp.Collections
10871087
[<CompiledName("Distinct")>]
10881088
let distinct source =
10891089
checkNonNull "source" source
1090+
if isEmpty source then empty else
10901091
seq { let hashSet = HashSet<'T>(HashIdentity.Structural<'T>)
10911092
for v in source do
10921093
if hashSet.Add(v) then
@@ -1095,6 +1096,7 @@ namespace Microsoft.FSharp.Collections
10951096
[<CompiledName("DistinctBy")>]
10961097
let distinctBy projection source =
10971098
checkNonNull "source" source
1099+
if isEmpty source then empty else
10981100
seq { let hashSet = HashSet<_>(HashIdentity.Structural<_>)
10991101
for v in source do
11001102
if hashSet.Add(projection v) then
@@ -1138,6 +1140,7 @@ namespace Microsoft.FSharp.Collections
11381140

11391141
let inline countByImpl (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (source:seq<'T>) =
11401142
checkNonNull "source" source
1143+
if isEmpty source then empty else
11411144

11421145
let dict = Dictionary comparer
11431146

0 commit comments

Comments
 (0)