Skip to content

Commit 0aa0043

Browse files
authored
Rollup merge of rust-lang#109287 - scottmcm:hash-slice-size-of-val, r=oli-obk
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 nsw`](https://rust.godbolt.org/z/Y9KxYETv5), so why not.
2 parents e81a072 + 3508879 commit 0aa0043

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler/rustc_codegen_ssa/src/glue.rs

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

library/core/src/hash/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ mod impls {
834834

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

0 commit comments

Comments
 (0)