Uh oh!
There was an error while loading. Please reload this page.
Implement TrustedRandomAccess for slice::{Chunks, ChunksMut, Windows} - #47142
Conversation
rust-highfive
commented
Jan 2, 2018
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
kennytm
commented
Jan 3, 2018
Thanks! @bors r+ |
bors
commented
Jan 3, 2018
📌 Commit 43291c6 has been approved by |
sdroege
commented
Jan 3, 2018
Thanks for the fast review! This is going to fail because of #47113 |
kennytm
commented
Jan 3, 2018
Okay. @bors r- |
sdroege
commented
Jan 3, 2018
For good measure, I'll also add unit tests for zipping the 3 iterators. It seems like this is not covered by any of the existing unit tests yet |
sdroege
commented
Jan 3, 2018
This will now fail until #47113 is merged for real |
bors
commented
Jan 3, 2018
☔ The latest upstream changes (presumably #47151) made this pull request unmergeable. Please resolve the merge conflicts. |
For testing if the TrustedRandomAccess implementation works.
rust-lang#47113 renamed the private size field to chunk_size for consistency.
bbb27f4 to
3f29e2bComparesdroege
commented
Jan 3, 2018
Rebased on top of latest master |
| unsafe impl<'a, T> TrustedRandomAccess for Chunks<'a, T> { | ||
| unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T] { | ||
| let start = i * self.chunk_size; | ||
| let end = cmp::min(start + self.chunk_size, self.v.len()); |
There was a problem hiding this comment.
There is a potential wraparound here isn't there? i is in bounds but start + size can still wrap around. In particular for [(); !0].chunks((!0)/2 +1) I think.
There was a problem hiding this comment.
It turns out Rust ICES on that array. For those that don't like my mobile-friendly syntax, !0 is the same as usize::max_value().
However Rust accepts a vec of this length, and we can demo (playground link)
fnmain(){let v = vec![(); !0];let iter = v.chunks((!0)/2 +1);for elt in iter {println!("Found chunk of len {}", elt.len());}}Which has output:
Found chunk of len 9223372036854775808
Found chunk of len 9223372036854775807
sdroege
commented
Jan 3, 2018
Good point, thanks. This should probably use Will fix in a few hours, thanks for spotting this |
I fixed that now Actually this all seems to have been investigated back then already, so it should all be fine. See top of #47126 (comment) |
sdroege
commented
Jan 4, 2018
I think we're good to go actually |
sdroege
commented
Jan 4, 2018
Some benchmark results, based on the code from #47115 (comment) . Just running a 1920*1080*4 byte array through the normal chunks version. Something like 1.5% difference (the new version is faster), but consistently. So even for things that llvm can't auto-vectorize it seems to be slightly faster. Before After |
kennytm
commented
Jan 4, 2018
Thanks again! Just wanna confirm, will the expression |
sdroege
commented
Jan 4, 2018
Yes, but only if you call it with an |
kennytm
commented
Jan 4, 2018
@bors r+ |
bors
commented
Jan 4, 2018
📌 Commit b69c124 has been approved by |
sdroege
commented
Jan 4, 2018
…s, r=kennytm
Implement TrustedRandomAccess for slice::{Chunks, ChunksMut, Windows}
As suggested by @bluss in rust-lang#47115 (comment)bors
commented
Jan 5, 2018
Implement TrustedRandomAccess for slice::{Chunks, ChunksMut, Windows}
As suggested by @bluss in #47115 (comment)bors
commented
Jan 5, 2018
☀️ Test successful - status-appveyor, status-travis |
As suggested by @bluss in #47115 (comment)