diff options
| author | Amos Onn <amosonn@gmail.com> | 2020-02-02 02:18:33 +0100 |
|---|---|---|
| committer | Amos Onn <amosonn@gmail.com> | 2020-02-03 01:03:33 +0100 |
| commit | 22b263ae1837ab6a64fe4bcdbfa07aa8883f57db (patch) | |
| tree | 87849e4cf6f838023f7ee4d7b9bb8aa4136a2339 /src/libcore/ptr | |
| parent | 3173cd1473eeebcc9567b686e63d281a761fd936 (diff) | |
| download | rust-22b263ae1837ab6a64fe4bcdbfa07aa8883f57db.tar.gz rust-22b263ae1837ab6a64fe4bcdbfa07aa8883f57db.zip | |
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.
Diffstat (limited to 'src/libcore/ptr')
| -rw-r--r-- | src/libcore/ptr/mod.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 805404b101b..0ee50966f96 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -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); } |
