Skip to content

Commit

Permalink
Shrink is_aligned_and_not_null
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Feb 3, 2024
1 parent 6dd581b commit 3ef4a60
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,10 @@ pub(crate) use assert_unsafe_precondition;
/// `align_of::<T>()`.
#[inline]
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
!ptr.is_null() && ptr.is_aligned()
let mask = crate::mem::align_of::<T>() - 1;
let is_aligned = (ptr.addr() & mask) == 0;
let not_null = ptr.addr() != 0;
is_aligned && not_null
}

/// Checks whether an allocation of `len` instances of `T` exceeds
Expand Down

0 comments on commit 3ef4a60

Please sign in to comment.