KEMBAR78
Remove unnecessary closures from Logging{Scope}HttpMessageHandler.SendCoreAsync by stephentoub · Pull Request #89160 · dotnet/runtime · GitHub
Skip to content

Conversation

stephentoub
Copy link
Member

The local async function is closing over the outer useAsync parameter, and because it's an async method, that closure is a class. Thus the decompiled method previously looked like:

private Task<HttpResponseMessage> SendCoreAsync(HttpRequestMessage request, bool useAsync, CancellationToken cancellationToken)
{
    <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0();
    <>c__DisplayClass5_.<>4__this = this;
    <>c__DisplayClass5_.useAsync = useAsync;
    System.ThrowHelper.ThrowIfNull(request, "request");
    return <>c__DisplayClass5_.<SendCoreAsync>g__Core|0(request, cancellationToken);
}

and with this change now looks like:

private Task<HttpResponseMessage> SendCoreAsync(HttpRequestMessage request, bool useAsync, CancellationToken cancellationToken)
{
    System.ThrowHelper.ThrowIfNull(request, "request");
    return <SendCoreAsync>g__Core|5_0(request, useAsync, cancellationToken);
}

@ghost
Copy link

ghost commented Jul 19, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

The local async function is closing over the outer useAsync parameter, and because it's an async method, that closure is a class. Thus the decompiled method previously looked like:

private Task<HttpResponseMessage> SendCoreAsync(HttpRequestMessage request, bool useAsync, CancellationToken cancellationToken)
{
    <>c__DisplayClass5_0 <>c__DisplayClass5_ = new <>c__DisplayClass5_0();
    <>c__DisplayClass5_.<>4__this = this;
    <>c__DisplayClass5_.useAsync = useAsync;
    System.ThrowHelper.ThrowIfNull(request, "request");
    return <>c__DisplayClass5_.<SendCoreAsync>g__Core|0(request, cancellationToken);
}

and with this change now looks like:

private Task<HttpResponseMessage> SendCoreAsync(HttpRequestMessage request, bool useAsync, CancellationToken cancellationToken)
{
    System.ThrowHelper.ThrowIfNull(request, "request");
    return <SendCoreAsync>g__Core|5_0(request, useAsync, cancellationToken);
}
Author: stephentoub
Assignees: stephentoub
Labels:

area-Extensions-HttpClientFactory

Milestone: -

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM

@stephentoub stephentoub merged commit 54c0756 into dotnet:main Jul 19, 2023
@stephentoub stephentoub deleted the removehttpclosure branch July 19, 2023 11:18
@karelz karelz added this to the 8.0.0 milestone Aug 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants