mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 21:08:32 +00:00
pr feedback
This commit is contained in:
@@ -8,18 +8,15 @@ impl<N: Unsigned + Clone> TestRandom for BitList<N> {
|
||||
let mut raw_bytes = smallvec![0; initial_len];
|
||||
rng.fill_bytes(&mut raw_bytes);
|
||||
|
||||
let highest_set_bit = raw_bytes
|
||||
let non_zero_bytes = raw_bytes
|
||||
.iter()
|
||||
.enumerate()
|
||||
.rev()
|
||||
.find(|(_, byte)| **byte > 0)
|
||||
.map(|(i, byte)| i * 8 + 7 - byte.leading_zeros() as usize)
|
||||
.find_map(|(i, byte)| (*byte > 0).then_some(i + 1))
|
||||
.unwrap_or(0);
|
||||
|
||||
let actual_len = highest_set_bit / 8 + 1;
|
||||
|
||||
if actual_len < initial_len {
|
||||
raw_bytes.truncate(actual_len);
|
||||
if non_zero_bytes < initial_len {
|
||||
raw_bytes.truncate(non_zero_bytes);
|
||||
}
|
||||
|
||||
Self::from_bytes(raw_bytes).expect("we generate a valid BitList")
|
||||
|
||||
Reference in New Issue
Block a user