C# Property pattern vs. type pattern #4809
-
Let discuss private record IntRecord ( int IntProperty ) { }
static IntRecord rec = new IntRecord(1);
private static void IL1 ()
{
_ = rec switch
{
{ IntProperty: 1 } => 'A',
};
}
private static void IL2 ()
{
_ = rec switch
{
IntRecord r when r.IntProperty == 1 => 'B',
};
} and their corresponding ILs
which differ singificantly only in Does diff (namely no-use pop/load to/from local var) result out of unoptimized implementation of Property Pattern or it follows some rules arising purely from the syntax – i.e. the IL2 explicitly uses the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
unnecessary stloc/ldloc pair should usually be suboptimal codegen. |
Beta Was this translation helpful? Give feedback.
-
Should this have been posted to dotnet/roslyn instead? Codegen is the compiler's task. |
Beta Was this translation helpful? Give feedback.
-
The IL you've posted doesn't match latest SharpLab, so I suspect it is already out of date. On SharpLab, both functions produce identical IL patterns in Release configuration. |
Beta Was this translation helpful? Give feedback.
The IL you've posted doesn't match latest SharpLab, so I suspect it is already out of date.
On SharpLab, both functions produce identical IL patterns in Release configuration.