From 65a3279f4a221e97c97ca1c49d89626c8700d017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 18 Dec 2021 20:41:58 +0100 Subject: [PATCH] Do not hash zero bytes of i64 and u32 in Sip128 hasher --- compiler/rustc_data_structures/src/sip128.rs | 18 ++++++++++++++++-- src/test/debuginfo/function-names.rs | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_data_structures/src/sip128.rs b/compiler/rustc_data_structures/src/sip128.rs index 53062b9c20da8..872b0eb7854ae 100644 --- a/compiler/rustc_data_structures/src/sip128.rs +++ b/compiler/rustc_data_structures/src/sip128.rs @@ -409,6 +409,20 @@ impl SipHasher128 { } } +macro_rules! dispatch_value { + ($target: expr, $value:expr) => { + let value = $value; + #[allow(unreachable_patterns)] + #[allow(overflowing_literals)] + match value { + 0..=0xFF => $target.short_write(value as u8), + 0x100..=0xFFFF => $target.short_write(value as u16), + 0x10000..=0xFFFFFFFF => $target.short_write(value as u32), + _ => $target.short_write(value as u64), + } + }; +} + impl Hasher for SipHasher128 { #[inline] fn write_u8(&mut self, i: u8) { @@ -422,7 +436,7 @@ impl Hasher for SipHasher128 { #[inline] fn write_u32(&mut self, i: u32) { - self.short_write(i); + dispatch_value!(self, i); } #[inline] @@ -452,7 +466,7 @@ impl Hasher for SipHasher128 { #[inline] fn write_i64(&mut self, i: i64) { - self.short_write(i as u64); + dispatch_value!(self, i as u64); } #[inline] diff --git a/src/test/debuginfo/function-names.rs b/src/test/debuginfo/function-names.rs index 61d5fc93cd2ad..ac9a02cce0481 100644 --- a/src/test/debuginfo/function-names.rs +++ b/src/test/debuginfo/function-names.rs @@ -37,7 +37,7 @@ // Const generic parameter // gdb-command:info functions -q function_names::const_generic_fn.* // gdb-check:[...]static fn function_names::const_generic_fn_bool(); -// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#fe3cfa0214ac55c7}>(); +// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#3fcd7c34c1555be6}>(); // gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>(); // gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>(); @@ -76,7 +76,7 @@ // Const generic parameter // cdb-command:x a!function_names::const_generic_fn* // cdb-check:[...] a!function_names::const_generic_fn_bool (void) -// cdb-check:[...] a!function_names::const_generic_fn_non_int (void) +// cdb-check:[...] a!function_names::const_generic_fn_non_int (void) // cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void) // cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)