Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 870
List.fold/contains simplification#3975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -212,15 +212,11 @@ namespace Microsoft.FSharp.Collections | ||
| [<CompiledName("Fold")>] | ||
| let fold<'T,'State> folder (state:'State) (list: 'T list) = | ||
| match list with | ||
| | [] -> state | ||
| | _ -> | ||
| let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder) | ||
| let rec loop s xs = | ||
| match xs with | ||
| | [] -> s | ||
| | h::t -> loop (f.Invoke(s,h)) t | ||
| loop state list | ||
| let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(folder) | ||
| let mutable acc = state | ||
| for x in list do | ||
| acc <- f.Invoke(acc, x) | ||
| acc | ||
| [<CompiledName("Pairwise")>] | ||
| let pairwise (list: 'T list) = | ||
| @@ -356,12 +352,10 @@ namespace Microsoft.FSharp.Collections | ||
| let exists predicate list = Microsoft.FSharp.Primitives.Basics.List.exists predicate list | ||
| [<CompiledName("Contains")>] | ||
| let inline contains value source = | ||
| let rec contains e xs1 = | ||
| match xs1 with | ||
| | [] -> false | ||
| | h1::t1 -> e = h1 || contains e t1 | ||
| contains value source | ||
| let rec contains value source = | ||
| ||
| match source with | ||
| | [] -> false | ||
| | h::t -> if h = value then true else contains value t | ||
| let rec exists2aux (f:OptimizedClosures.FSharpFunc<_,_,_>) list1 list2 = | ||
| match list1,list2 with | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This optimization for the case where the list is empty has been removed - can it please be added back in? Or lets just not do this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsyme Thanks, I'll add it. The optimization for the empty case is still there to some extent, in the sense that the folding function is not being called in the "empty list" case. But yes, additional check in the beginning for the empty case makes a lot of sense, so the Adapt function is not called prematurely. I'll resubmit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I integrated the revert so you can submit a new PR at your leisure :) thanks all!