Skip to content

Commit 22b263a

Browse files
committed
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.
1 parent 3173cd1 commit 22b263a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/libcore/ptr/mod.rs

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

0 commit comments

Comments
 (0)