]> git.lizzy.rs Git - rust.git/commit
Get rid of bounds check in slice::chunks_exact() and related functions during constru...
authorSebastian Dröge <sebastian@centricular.com>
Wed, 26 Aug 2020 06:59:04 +0000 (09:59 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 30 Aug 2020 20:13:47 +0000 (23:13 +0300)
commitd08996ac543b4d330bef790ff9f727e99c7a539c
tree554b264fd6cb49b27723ea87533224ed82b38df4
parent30dc32b10eb53e4a92c61a42062983db58838217
Get rid of bounds check in slice::chunks_exact() and related functions 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.
library/core/src/slice/mod.rs