-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This is inspired by ndarray and generally seems to allow llvm to remove more bounds checks in the code using the iterator (because the slices will always be exactly the requested size), and doesn't require the caller to add additional checks.
A PR adding these for further discussion will come in a bit.
- Implemented in Add slice::ExactChunks and ::ExactChunksMut iterators #47126
Open questions:
- Should the new iterators panic if the slice is not divisible by the
chunk_size
, or omit any leftover elements.
The latter is implemented right now and very similar to howzip
works and @shepmaster even argues that without this, this iterator is kind of useless and the optimization should be implemented as part of the normal chunks iterator (which seems non-trivial, see ).
Omission of leftover elements is also how this iterator is implemented in ndarray (but far more general).
A function for getting access to the remainder exists on the iterator, similar to how `slice::Iter` and `slice::IterMut` give access to the tail (note: the remainder are the odd elements that don't completely fill a chunk, it's not the tail!)
**The majority of people (who spoke up here) seem to prefer the non-panicking behaviour**
- [x] Should it be called `exact_chunks` or `chunks_exact`? The former is how it's called in `ndarray`, the latter is [potentially more discoverable](https://github.com/rust-lang/rust/issues/47115#issuecomment-403090815) in e.g. IDEs.
**It was renamed to `chunks_exact`**
kornelski and 0e4ef622
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.