Use iterators for num_diff_bits

Signed-off-by: Joe Richey <joerichey@google.com>
This commit is contained in:
Joe Richey 2022-10-22 13:52:42 -07:00
parent c83edb650b
commit b893cb9c77

View File

@ -16,11 +16,10 @@ fn test_zero() {
#[cfg(not(feature = "custom"))]
fn num_diff_bits(s1: &[u8], s2: &[u8]) -> usize {
assert_eq!(s1.len(), s2.len());
let mut n = 0;
for i in 0..s1.len() {
n += (s1[i] ^ s2[i]).count_ones() as usize;
}
n
s1.iter()
.zip(s2.iter())
.map(|(a, b)| (a ^ b).count_ones() as usize)
.sum()
}
// Tests the quality of calling getrandom on two large buffers