make src into a range and get rid of count#1
Conversation
|
(Note that this is ~half of my suggestion, I also proposed changing |
|
Here's an example instantiation to look at the difference: https://godbolt.org/z/PsxH7K It seems like a few instructions get added to the caller in this case, probably too small of a difference to be measurable? |
src/lib.rs
Outdated
| Bound::Unbounded => 0, | ||
| }; | ||
| let src_end = match src.end_bound() { | ||
| Bound::Included(&n) => n.saturating_add(1), |
There was a problem hiding this comment.
I wonder if this is technically correct. If a slice actually ends at the largest possible address (I think that's one less than the maximum representable, to allow C to compute the p + len pointer?), then an inclusive range that passes the end of the slice by one would be converted from the panic it should be to a valid range one element shorter than the caller asked for.
|
Playing with this a little more, I think it's obviously better to read and write than my original API. I'm going to land it here and update the Rust PR. |
This is an example implementation of a change @SimonSapin suggested in rust-lang/rust#53652 (comment).