Use size_of_val instead of manual calculation

Very minor thing that I happened to notice in passing, but it's both shorter and means it gets `mul nuw`, so why not.
This commit is contained in:
Scott McMurray 2023-03-17 19:29:23 -07:00
parent e4b9f86054
commit 35088797ae
2 changed files with 2 additions and 2 deletions

View File

@ -46,7 +46,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul` // NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
// (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication // (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
// cannot signed wrap, and that both operands are non-negative. But at the time of writing, // cannot signed wrap, and that both operands are non-negative. But at the time of writing,
// `BuilderMethods` can't do this, and it doesn't seem to enable any further optimizations. // the `LLVM-C` binding can't do this, and it doesn't seem to enable any further optimizations.
bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())), bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
bx.const_usize(unit.align.abi.bytes()), bx.const_usize(unit.align.abi.bytes()),
) )

View File

@ -834,7 +834,7 @@ fn hash<H: ~const Hasher>(&self, state: &mut H) {
#[inline] #[inline]
fn hash_slice<H: ~const Hasher>(data: &[$ty], state: &mut H) { fn hash_slice<H: ~const Hasher>(data: &[$ty], state: &mut H) {
let newlen = data.len() * mem::size_of::<$ty>(); let newlen = mem::size_of_val(data);
let ptr = data.as_ptr() as *const u8; let ptr = data.as_ptr() as *const u8;
// SAFETY: `ptr` is valid and aligned, as this macro is only used // SAFETY: `ptr` is valid and aligned, as this macro is only used
// for numeric primitives which have no padding. The new slice only // for numeric primitives which have no padding. The new slice only