Skip to content

Potential optimization for is "" #41779

@Youssef1313

Description

@Youssef1313

Based on the current master in sharplab:

https://sharplab.io/#v2:EYLgtghgzgLgpgJwD4AEDMACFAmDBhAWACgBvYjCrTYAexoBsMBZAChuACs4BjGDADwCU5SmSKUJWAOwCMASygYAREoDcIigF9imoA==

The following:

public bool M(object x)
{
    return x is "";
}

is compiled as:

public bool M(object x)
{
    string text = x as string;
    if (text != null)
    {
        return text == "";
    }
    return false;
}

It's a bit more performant if return text == "" is text.Length == 0.
That would be a special-casing for this, which I'm unsure if it's acceptable to the compiler team or not.

category:cq
theme:basic-cq
skill-level:intermediate
cost:small

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions