From a44d80006a65ae291bded0ee8a0a15db324a56b0 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 10 Mar 2019 21:07:09 +1100 Subject: [PATCH] Improve allocation in get_attestation_participants --- eth2/types/src/beacon_state.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 39970b9a7..603ae2f9d 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -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) }