Skip to content

Commit 9e7a319

Browse files
committed
Replace u8to64_le macro with u64::from_le_bytes
The macro was a reimplementation of the function.
1 parent c842240 commit 9e7a319

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

library/core/tests/hash/sip.rs

+2-24
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@ impl<'a> Hash for Bytes<'a> {
1515
}
1616
}
1717

18-
macro_rules! u8to64_le {
19-
($buf:expr, $i:expr) => {
20-
$buf[0 + $i] as u64
21-
| ($buf[1 + $i] as u64) << 8
22-
| ($buf[2 + $i] as u64) << 16
23-
| ($buf[3 + $i] as u64) << 24
24-
| ($buf[4 + $i] as u64) << 32
25-
| ($buf[5 + $i] as u64) << 40
26-
| ($buf[6 + $i] as u64) << 48
27-
| ($buf[7 + $i] as u64) << 56
28-
};
29-
($buf:expr, $i:expr, $len:expr) => {{
30-
let mut t = 0;
31-
let mut out = 0;
32-
while t < $len {
33-
out |= ($buf[t + $i] as u64) << t * 8;
34-
t += 1;
35-
}
36-
out
37-
}};
38-
}
39-
4018
fn hash_with<H: Hasher, T: Hash>(mut st: H, x: &T) -> u64 {
4119
x.hash(&mut st);
4220
st.finish()
@@ -123,7 +101,7 @@ fn test_siphash_1_3() {
123101
let mut state_inc = SipHasher13::new_with_keys(k0, k1);
124102

125103
while t < 64 {
126-
let vec = u8to64_le!(vecs[t], 0);
104+
let vec = u64::from_le_bytes(vecs[t]);
127105
let out = hash_with(SipHasher13::new_with_keys(k0, k1), &Bytes(&buf));
128106
assert_eq!(vec, out);
129107

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

219197
while t < 64 {
220-
let vec = u8to64_le!(vecs[t], 0);
198+
let vec = u64::from_le_bytes(vecs[t]);
221199
let out = hash_with(SipHasher::new_with_keys(k0, k1), &Bytes(&buf));
222200
assert_eq!(vec, out);
223201

0 commit comments

Comments
 (0)