Skip to content

Commit

Permalink
Optimize pointer::as_aligned_to
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Aug 5, 2022
1 parent 497c220 commit fbcafb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,8 @@ impl<T: ?Sized> *const T {
panic!("is_aligned_to: align is not a power-of-two");
}

// SAFETY: `is_power_of_two()` will return `false` for zero.
unsafe { core::intrinsics::assume(align != 0) };

// Cast is needed for `T: !Sized`
self.cast::<u8>().addr() % align == 0
self.cast::<u8>().addr() & align - 1 == 0
}
}

Expand Down
5 changes: 1 addition & 4 deletions core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,11 +1614,8 @@ impl<T: ?Sized> *mut T {
panic!("is_aligned_to: align is not a power-of-two");
}

// SAFETY: `is_power_of_two()` will return `false` for zero.
unsafe { core::intrinsics::assume(align != 0) };

// Cast is needed for `T: !Sized`
self.cast::<u8>().addr() % align == 0
self.cast::<u8>().addr() & align - 1 == 0
}
}

Expand Down

0 comments on commit fbcafb8

Please sign in to comment.