Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CrazyboyQCD opened this issue Oct 28, 2024 · 0 comments
Closed
Labels
A-patterns Relating to patterns and pattern matching C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CrazyboyQCD
Copy link

CrazyboyQCD commented Oct 28, 2024

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.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 28, 2024
@CrazyboyQCD CrazyboyQCD changed the title Suboptimal codegen for u8 slice matching without | Suboptimal codegen for slice matching without | Oct 28, 2024
@workingjubilee workingjubilee added A-patterns Relating to patterns and pattern matching C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 1, 2024
@CrazyboyQCD CrazyboyQCD changed the title Suboptimal codegen for slice matching without | Suboptimal codegen for integer slice matching without | Nov 1, 2024
@CrazyboyQCD CrazyboyQCD changed the title Suboptimal codegen for integer slice matching without | Suboptimal codegen for integer slice matching without | in inner elements Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants