Skip to content

Commit b893cb9

Browse files
committed
Use iterators for num_diff_bits
Signed-off-by: Joe Richey <[email protected]>
1 parent c83edb6 commit b893cb9

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/common/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ fn test_zero() {
1616
#[cfg(not(feature = "custom"))]
1717
fn num_diff_bits(s1: &[u8], s2: &[u8]) -> usize {
1818
assert_eq!(s1.len(), s2.len());
19-
let mut n = 0;
20-
for i in 0..s1.len() {
21-
n += (s1[i] ^ s2[i]).count_ones() as usize;
22-
}
23-
n
19+
s1.iter()
20+
.zip(s2.iter())
21+
.map(|(a, b)| (a ^ b).count_ones() as usize)
22+
.sum()
2423
}
2524

2625
// Tests the quality of calling getrandom on two large buffers

0 commit comments

Comments
 (0)