Skip to content

Optimizing "constant_string".Length #5310

@jamesqo

Description

@jamesqo

Lots of times for readability I use "constant_string".Length instead of 15 in my code. For example:

string TextAfterFoo(string s) =>
    s.Substring(s.IndexOf("Foo") + "Foo".Length); // a lot more readable than `3`

It would be nice if RyuJIT could optimize this as a JIT-time constant, so a string wouldn't have to actually be loaded and called Length on.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions