Skip to content

List.fold IL simplification#3982

Merged
KevinRansom merged 1 commit into
dotnet:masterfrom
ncave:master
Nov 22, 2017
Merged

List.fold IL simplification#3982
KevinRansom merged 1 commit into
dotnet:masterfrom
ncave:master

Conversation

@ncave

@ncave ncave commented Nov 20, 2017

Copy link
Copy Markdown
Contributor

before:

public static TState Fold<T, TState>(FSharpFunc<TState, FSharpFunc<T, TState>> folder, TState state, FSharpList<T> list)
{
	if (list.tail == null)
	{
		return state;
	}
	OptimizedClosures.FSharpFunc<TState, T, TState> f = OptimizedClosures.FSharpFunc<TState, T, TState>.Adapt(folder);
	return ListModule.loop@219-29<T, TState>(f, state, list);
}

internal static TState loop@219-29<T, TState>(OptimizedClosures.FSharpFunc<TState, T, TState> f, TState s, FSharpList<T> xs)
{
	while (xs.tail != null)
	{
		FSharpList<T> fsharpList = xs;
		FSharpList<T> tail = fsharpList.tail;
		T head = fsharpList.head;
		OptimizedClosures.FSharpFunc<TState, T, TState> fsharpFunc = f;
		TState tstate = f.Invoke(s, head);
		xs = tail;
		s = tstate;
		f = fsharpFunc;
	}
	return s;
}

after:

public static TState Fold<T, TState>(FSharpFunc<TState, FSharpFunc<T, TState>> folder, TState state, FSharpList<T> list)
{
	if (list.tail == null)
	{
		return state;
	}
	OptimizedClosures.FSharpFunc<TState, T, TState> fsharpFunc = OptimizedClosures.FSharpFunc<TState, T, TState>.Adapt(folder);
	TState tstate = state;
	FSharpList<T> fsharpList = list;
	for (FSharpList<T> tail = fsharpList.tail; tail != null; tail = fsharpList.tail)
	{
		T head = fsharpList.head;
		tstate = fsharpFunc.Invoke(tstate, head);
		fsharpList = tail;
	}
	return tstate;
}

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this

@dsyme

dsyme commented Nov 21, 2017

Copy link
Copy Markdown
Contributor

Super, thanks

@KevinRansom KevinRansom merged commit 9ef05a7 into dotnet:master Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants