Skip to content

Commit 65a3279

Browse files
committed
Do not hash zero bytes of i64 and u32 in Sip128 hasher
1 parent b5da808 commit 65a3279

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: compiler/rustc_data_structures/src/sip128.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ impl SipHasher128 {
409409
}
410410
}
411411

412+
macro_rules! dispatch_value {
413+
($target: expr, $value:expr) => {
414+
let value = $value;
415+
#[allow(unreachable_patterns)]
416+
#[allow(overflowing_literals)]
417+
match value {
418+
0..=0xFF => $target.short_write(value as u8),
419+
0x100..=0xFFFF => $target.short_write(value as u16),
420+
0x10000..=0xFFFFFFFF => $target.short_write(value as u32),
421+
_ => $target.short_write(value as u64),
422+
}
423+
};
424+
}
425+
412426
impl Hasher for SipHasher128 {
413427
#[inline]
414428
fn write_u8(&mut self, i: u8) {
@@ -422,7 +436,7 @@ impl Hasher for SipHasher128 {
422436

423437
#[inline]
424438
fn write_u32(&mut self, i: u32) {
425-
self.short_write(i);
439+
dispatch_value!(self, i);
426440
}
427441

428442
#[inline]
@@ -452,7 +466,7 @@ impl Hasher for SipHasher128 {
452466

453467
#[inline]
454468
fn write_i64(&mut self, i: i64) {
455-
self.short_write(i as u64);
469+
dispatch_value!(self, i as u64);
456470
}
457471

458472
#[inline]

Diff for: src/test/debuginfo/function-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Const generic parameter
3838
// gdb-command:info functions -q function_names::const_generic_fn.*
3939
// gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
40-
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#fe3cfa0214ac55c7}>();
40+
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#3fcd7c34c1555be6}>();
4141
// gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
4242
// gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
4343

@@ -76,7 +76,7 @@
7676
// Const generic parameter
7777
// cdb-command:x a!function_names::const_generic_fn*
7878
// cdb-check:[...] a!function_names::const_generic_fn_bool<false> (void)
79-
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$fe3cfa0214ac55c7> (void)
79+
// cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$3fcd7c34c1555be6> (void)
8080
// cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void)
8181
// cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)
8282

0 commit comments

Comments
 (0)