File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -212,11 +212,15 @@ namespace Microsoft.FSharp.Collections
212212
213213 [<CompiledName( " Fold" ) >]
214214 let fold < 'T , 'State > folder ( state : 'State ) ( list : 'T 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
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
220224
221225 [<CompiledName( " Pairwise" ) >]
222226 let pairwise ( list : 'T list ) =
@@ -352,10 +356,12 @@ namespace Microsoft.FSharp.Collections
352356 let exists predicate list = Microsoft.FSharp.Primitives.Basics.List.exists predicate list
353357
354358 [<CompiledName( " Contains" ) >]
355- let rec contains value source =
356- match source with
357- | [] -> false
358- | h:: t -> if h = value then true else contains value t
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
359365
360366 let rec exists2aux ( f : OptimizedClosures.FSharpFunc < _ , _ , _ >) list1 list2 =
361367 match list1, list2 with
Original file line number Diff line number Diff 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 contains : value : 'T -> source : 'T list -> bool when 'T : equality
105+ val inline 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.
You can’t perform that action at this time.
0 commit comments