Skip to content

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Aug 20, 2022

GetValueOrDefault was used to avoid null check in Nullable<T>.Value. JIT in .NET 5/6/7 optimizes this away.

There probably is a very small perf hit on older platforms (.NET Framework/.NET Core 3), but IMO the easier-to-read and safer code is better.

Copy link
Contributor

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

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

GetValueOrDefault was used to avoid null check in Nullable<T>.Value. JIT in .NET 5/6/7 optimizes this away.

To state more precisely: only when the JIT can prove that there was a HasValue or != null check before.

@JamesNK JamesNK merged commit 4f06b60 into grpc:master Aug 24, 2022
@JamesNK JamesNK deleted the jamesnk/nullable-value branch August 24, 2022 06:20
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