Skip to content

Slicing after [u8]::first performs unnessessary bound check #75268

Closed
@youknowone

Description

@youknowone

Playground link: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=2e2d548aa3a7b89bfb074456d971450d

pub fn boundcheck(mut lit: &[u8]) -> Option<&[u8]> {
    if lit.first() == Some(&b'_') {
        lit = &lit[1..];
        // lit = unsafe { lit.get_unchecked(1..) };
    }
    Some(lit)
}

This slice always exists because of the branch, but it performs bound check.

Real case: RustPython/RustPython#2077

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-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