Improve allocation in get_attestation_participants

This commit is contained in:
Paul Hauner 2019-03-10 21:07:09 +11:00
parent 53456a6c79
commit a44d80006a
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -531,12 +531,14 @@ impl BeaconState {
return Err(Error::InvalidBitfield);
}
let mut participants = vec![];
let mut participants = Vec::with_capacity(committee.len());
for (i, validator_index) in committee.iter().enumerate() {
if bitfield.get(i).unwrap() {
participants.push(*validator_index);
match bitfield.get(i) {
Ok(bit) if bit == true => participants.push(*validator_index),
_ => {}
}
}
participants.shrink_to_fit();
Ok(participants)
}