Skip to content

Commit d8544fe

Browse files
ncaveKevinRansom
authored andcommitted
minor IL simplification (#3975)
1 parent e0596f3 commit d8544fe

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/fsharp/FSharp.Core/list.fs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,11 @@ namespace Microsoft.FSharp.Collections
212212

213213
[<CompiledName("Fold")>]
214214
let fold<'T,'State> folder (state:'State) (list: 'T list) =
215-
match list with
216-
| [] -> state
217-
| _ ->
218-
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder)
219-
let rec loop s xs =
220-
match xs with
221-
| [] -> s
222-
| h::t -> loop (f.Invoke(s,h)) t
223-
loop state list
215+
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder)
216+
let mutable acc = state
217+
for x in list do
218+
acc <- f.Invoke(acc, x)
219+
acc
224220

225221
[<CompiledName("Pairwise")>]
226222
let pairwise (list: 'T list) =
@@ -356,12 +352,10 @@ namespace Microsoft.FSharp.Collections
356352
let exists predicate list = Microsoft.FSharp.Primitives.Basics.List.exists predicate list
357353

358354
[<CompiledName("Contains")>]
359-
let inline contains value source =
360-
let rec contains e xs1 =
361-
match xs1 with
362-
| [] -> false
363-
| h1::t1 -> e = h1 || contains e t1
364-
contains value source
355+
let rec contains value source =
356+
match source with
357+
| [] -> false
358+
| h::t -> if h = value then true else contains value t
365359

366360
let rec exists2aux (f:OptimizedClosures.FSharpFunc<_,_,_>) list1 list2 =
367361
match list1,list2 with

src/fsharp/FSharp.Core/list.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace Microsoft.FSharp.Collections
102102
/// <param name="source">The input list.</param>
103103
/// <returns>True if the input list contains the specified element; false otherwise.</returns>
104104
[<CompiledName("Contains")>]
105-
val inline contains: value:'T -> source:'T list -> bool when 'T : equality
105+
val contains: value:'T -> source:'T list -> bool when 'T : equality
106106

107107
/// <summary>Returns a list that contains no duplicate entries according to generic hash and
108108
/// equality comparisons on the entries.

0 commit comments

Comments
 (0)