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

Use throw helpers in a few more places #82533

Merged
merged 3 commits into from Feb 23, 2023

Conversation

stephentoub
Copy link
Member

No description provided.

Copy link
Contributor

@xtqqczze xtqqczze left a comment

Choose a reason for hiding this comment

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

Don't forgot the nullable annotations :)

@xtqqczze
Copy link
Contributor

I believe MemberNotNullAttribute may provide a benefit similar to DoesNotReturnAttribute, as code analysis can determine the method will not return when the member is null.

@stephentoub
Copy link
Member Author

I believe MemberNotNullAttribute may provide a benefit similar to DoesNotReturnAttribute, as code analysis can determine the method will not return when the member is null.

These methods are private. If the caller doesn't try to dereference the cited member, such attribution doesn't help with anything.

@stephentoub stephentoub merged commit f8b9b8d into dotnet:main Feb 23, 2023
@stephentoub stephentoub deleted the morethrowhelper branch February 23, 2023 23:00
@@ -295,13 +295,19 @@ private static unsafe string Ctor(ReadOnlySpan<char> value)

public static string Create<TState>(int length, TState state, SpanAction<char, TState> action)
{
ArgumentNullException.ThrowIfNull(action);
if (action is null)
Copy link
Contributor

@drieseng drieseng Feb 25, 2023

Choose a reason for hiding this comment

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

@stephentoub: Just out of curiosity, why was this changed?

PS. I should sleep more :(

Copy link
Member Author

Choose a reason for hiding this comment

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

This pattern results in ever so slightly smaller asm, and as it's in a generic method and we already had the helper and the appropriately named constant argument and I was already editing the method, it was trivial to switch.

@dotnet dotnet locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants