Conversation
This comment has been minimized.
This comment has been minimized.
eccda83 to
4c4a61b
Compare
This comment has been minimized.
This comment has been minimized.
4c4a61b to
4a0dbad
Compare
library/core/src/array/mod.rs
Outdated
| return Err(unsafe { IntoIter::new_unchecked(array, 0..initialized) }); | ||
| } else { | ||
| // SAFETY: must be at least N elements; safe to unwrap N elements. | ||
| return Ok(from_fn(|_| unsafe { self.next().unwrap_unchecked() })); |
There was a problem hiding this comment.
unsure: Since you're specializing anyway, maybe https://std.noratrieb.dev/x86_64-unknown-linux-gnu/core/iter/traits/unchecked_iterator/trait.UncheckedIterator.html#method.next_unchecked instead?
| return Ok(from_fn(|_| unsafe { self.next().unwrap_unchecked() })); | |
| return Ok(from_fn(|_| unsafe { self.next_unchecked() })); |
There was a problem hiding this comment.
oh yeah i was looking for that but i couldnt find it 😔
idk why it isnt in my docs
There was a problem hiding this comment.
but theres only like six things that are uncheckediterator?
unless theres a blanket impl im missing
There was a problem hiding this comment.
uncheckediterator is also not actually spec-on-able, i'd have to add the marker thing
|
r? the8472 |
4a0dbad to
18a71c8
Compare
library/core/src/array/mod.rs
Outdated
| ) -> Result<[T; N], IntoIter<T, N>> { | ||
| iter.spec_next_chunk() | ||
| } | ||
| #[inline] |
There was a problem hiding this comment.
the attribute should go after the doc comment
library/core/src/array/mod.rs
Outdated
| // SAFETY: Has to error out; trusted len means that | ||
| // SAFETY: there may only be less than N elements |
There was a problem hiding this comment.
| // SAFETY: Has to error out; trusted len means that | |
| // SAFETY: there may only be less than N elements | |
| // SAFETY: Has to error out; trusted len means that | |
| // there may only be less than N elements |
it doesn't need to be repeated for every line
There was a problem hiding this comment.
yeah i thought so, and was confused, so i put that in, but it turned out it was mad because the unsafe block was on the next line due to formatting, mb
| Err(unsafe { IntoIter::new_unchecked(array, 0..initialized) }) | ||
| } else { | ||
| // SAFETY: must be at least N elements; safe to unwrap N elements. | ||
| Ok(from_fn(|_| unsafe { self.next().unwrap_unchecked() })) |
There was a problem hiding this comment.
The default impl uses an uninit array for either case and moves that into the result. If the stars struct layouts align maybe that results in fewer moves. Have you checked in godbolt whether this is fine?
There was a problem hiding this comment.
let me see if using the same array makes any difference.
There was a problem hiding this comment.
doesn't seem to make a difference for my test case
| /// If `iter.next()` panics, all items already yielded by the iterator are | ||
| /// dropped. | ||
| /// | ||
| /// Used for [`Iterator::next_chunk`]. |
There was a problem hiding this comment.
The documentation should go in the pub(crate) fn since that's what gets called on other modules and someone might want to get docs for.
| } | ||
| impl<I: Iterator<Item = T>, T, const N: usize> SpecNextChunk<T, N> for I { | ||
| default fn spec_next_chunk(&mut self) -> Result<[T; N], IntoIter<T, N>> { | ||
| generic_iter_next_chunk(self) |
There was a problem hiding this comment.
we could just inline the code here, there doesn't seem to be any reason for the indirection.
| let initialized = | ||
| // SAFETY: Has to error out; trusted len means that | ||
| // SAFETY: there may only be less than N elements | ||
| unsafe { iter_next_chunk_erased(&mut array, self).unwrap_err_unchecked() }; |
There was a problem hiding this comment.
I suspect that going through that method doesn't give us the benefit of TrustedLen, if it doesn't see that next can never fail.
There was a problem hiding this comment.
on the error case? the error case wasnt very different when i used the next().unwrap_unchecked(), i looked at the asm a little and it was identical versus reusing that method. im not completely sure why, however its the slow path anyway.
18391e2 to
65349e7
Compare
65349e7 to
54a49a3
Compare
relevant to #98326