Optimize core::ptr::align_offset

- As explained in the comment inside mod_inv, it is valid to work mod
  `usize::max_value()` right until the end.
This commit is contained in:
Amos Onn 2020-02-02 02:18:33 +01:00
parent 3173cd1473
commit 22b263ae18

View File

@ -1081,8 +1081,7 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
// uses e.g., subtraction `mod n`. It is entirely fine to do them `mod
// usize::max_value()` instead, because we take the result `mod n` at the end
// anyway.
inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse)))
& (going_mod - 1);
inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse)));
if going_mod >= m {
return inverse & (m - 1);
}