Skip to content

Suboptimal codegen for integer slice matching without | in inner elements #132254

Open
@CrazyboyQCD

Description

In maching without |, this is not optimized as slice compare:

let s: &[u8];
match s {
    &[b'a', b'b', ... , ..] => ...
    _ => ...,
}

Slice compare:

let s: &[u8];
let target = b"...";
if s.len() >= target.len() && &s[..target.len()] == target {
 ...
} else {
 ...
}

Integer: https://godbolt.org/z/csxf5zeYs
&str: https://godbolt.org/z/3Yr5nac3r
Not sure if this shoud be integer only.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-patternsRelating to patterns and pattern matchingC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions