To make "Assign if variable is not null, otherwise skip" be shorter #4147
-
at present
the current shortest is
but it still assign one time when variable is null.Test:
consider to make it be shorter and faster? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think this should be opened at dotnet/Roslyn as it didn't require any language changes. |
Beta Was this translation helpful? Give feedback.
-
Those IL snippets look incomplete, and possibly also from a Debug build? Also, the length of the IL doesn't really mean much: check the ASM, and benchmark the two cases to see which is faster. Note that the IL will necessarily be different in those two cases, as the null coalescing operator guarantees that variable` is read only once. |
Beta Was this translation helpful? Give feedback.
-
(Copied to dotnet/roslyn#49427) |
Beta Was this translation helpful? Give feedback.
I think this should be opened at dotnet/Roslyn as it didn't require any language changes.