mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
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:
parent
3173cd1473
commit
22b263ae18
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user