3 ms·
Just because indexing is bounds-checked by default doesn't mean that the bounds-checking is necessarily in your final code: https://rust.godbolt.org/z/er9Phcr3
by froydnj 5y ago
Just because indexing is bounds-checked by default doesn't mean that the bounds-checking is necessarily in your final code:
https://rust.godbolt.org/z/er9Phcr3c https://rust.godbolt.org/z/er9Phcr3c
Yes, you still have the bounds check when constructing the slice, but that's fine.
And since it's probably slightly more common to iterate over the length of the vector anyway:
https://rust.godbolt.org/z/e5sdTb7vK https://rust.godbolt.org/z/e5sdTb7vK