Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace u8to64_le macro with u64::from_le_bytes #96156

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions library/core/tests/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@ impl<'a> Hash for Bytes<'a> {
}
}

macro_rules! u8to64_le {
($buf:expr, $i:expr) => {
$buf[0 + $i] as u64
| ($buf[1 + $i] as u64) << 8
| ($buf[2 + $i] as u64) << 16
| ($buf[3 + $i] as u64) << 24
| ($buf[4 + $i] as u64) << 32
| ($buf[5 + $i] as u64) << 40
| ($buf[6 + $i] as u64) << 48
| ($buf[7 + $i] as u64) << 56
};
($buf:expr, $i:expr, $len:expr) => {{
let mut t = 0;
let mut out = 0;
while t < $len {
out |= ($buf[t + $i] as u64) << t * 8;
t += 1;
}
out
}};
}

fn hash_with<H: Hasher, T: Hash>(mut st: H, x: &T) -> u64 {
x.hash(&mut st);
st.finish()
Expand Down Expand Up @@ -123,7 +101,7 @@ fn test_siphash_1_3() {
let mut state_inc = SipHasher13::new_with_keys(k0, k1);

while t < 64 {
let vec = u8to64_le!(vecs[t], 0);
let vec = u64::from_le_bytes(vecs[t]);
let out = hash_with(SipHasher13::new_with_keys(k0, k1), &Bytes(&buf));
assert_eq!(vec, out);

Expand Down Expand Up @@ -217,7 +195,7 @@ fn test_siphash_2_4() {
let mut state_inc = SipHasher::new_with_keys(k0, k1);

while t < 64 {
let vec = u8to64_le!(vecs[t], 0);
let vec = u64::from_le_bytes(vecs[t]);
let out = hash_with(SipHasher::new_with_keys(k0, k1), &Bytes(&buf));
assert_eq!(vec, out);

Expand Down