Skip to content
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

Remove unnecessary closures from Logging{Scope}HttpMessageHandler.SendCoreAsync #89160

Merged
merged 3 commits into from
Jul 19, 2023

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
101 of 103 checks passed
@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