dotnet/roslyn

Codegen of System.Nullable `is null` check is poor

Open

#65.091 aperta il 28 ott 2022

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
4 - In ReviewArea-CompilersCode Gen QualityConcept-Design Debthelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

Codegen of System.Nullable is null check is poor

Take a look at: https://sharplab.io/#v2:C4LglgNgPgAgLAAgAoHsUCcDCKAmBTAczwDsAKMYhC4AfgQDcBKAWACgBvNhbqgMwVL0qAZwTEArhAiMEXHvJgB2ANxsAvmzbwEAcTQ5s+ImQpVitBiw5zuYfqQCE9AHQAJAIbCAau4ji8MjbyCEqqrBqsWoh6uIaEJABM5JTUdExsnKzydgJCALx5YpLSslnB3KHqQA

void PoorCodegen(in int? v)
{
    if (v is null) 
        return;
}

void GoodCodegen(in int? v)
{
    if (!v.HasValue) 
        return;
}

void GoodCodegen2(in int? v)
{
    if (v == null) 
        return;
}

In the pattern matching case there suddenly is a copy.

Guida contributor