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

Get rid of bounds check in slice::chunks_exact() and related function… #75936

Merged
merged 3 commits into from
Aug 31, 2020

Commits on Aug 30, 2020

  1. Add (non-public) slice::split_at_unchecked() and split_at_mut_uncheck…

    …ed()
    
    These are unsafe variants of the non-unchecked functions and don't do
    any bounds checking.
    
    For the time being these are not public and only a preparation for the
    following commit. Making it public and stabilization can follow later
    and be discussed in rust-lang#76014 .
    sdroege committed Aug 30, 2020
    Configuration menu
    Copy the full SHA
    30dc32b View commit details
    Browse the repository at this point in the history
  2. Get rid of bounds check in slice::chunks_exact() and related function…

    …s during construction
    
    LLVM can't figure out in
    
        let rem = self.len() % chunk_size;
        let len = self.len() - rem;
        let (fst, snd) = self.split_at(len);
    
    and
    
        let rem = self.len() % chunk_size;
        let (fst, snd) = self.split_at(rem);
    
    that the index passed to split_at() is smaller than the slice length and
    adds a bounds check plus panic for it.
    
    Apart from removing the overhead of the bounds check this also allows
    LLVM to optimize code around the ChunksExact iterator better.
    sdroege committed Aug 30, 2020
    Configuration menu
    Copy the full SHA
    d08996a View commit details
    Browse the repository at this point in the history
  3. Improve documentation of slice::get_unchecked() / split_at_unchecked()

    Thanks to Ivan Tham, who gave the majority of these suggestions during
    their review.
    sdroege committed Aug 30, 2020
    Configuration menu
    Copy the full SHA
    8d3cf92 View commit details
    Browse the repository at this point in the history