Avoid growing Vec for sync committee indices (#3301)
## Issue Addressed NA ## Proposed Changes This is a fairly simple micro-optimization to avoid using `Vec::grow`. I don't believe this will have a substantial effect on block processing times, however it was showing up in flamegraphs. I think it's worth making this change for general memory-hygiene. ## Additional Info NA
This commit is contained in:
parent
a7da0677d5
commit
e5212f1320
@ -779,14 +779,14 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
sync_committee: &SyncCommittee<T>,
|
sync_committee: &SyncCommittee<T>,
|
||||||
) -> Result<Vec<usize>, Error> {
|
) -> Result<Vec<usize>, Error> {
|
||||||
sync_committee
|
let mut indices = Vec::with_capacity(sync_committee.pubkeys.len());
|
||||||
.pubkeys
|
for pubkey in sync_committee.pubkeys.iter() {
|
||||||
.iter()
|
indices.push(
|
||||||
.map(|pubkey| {
|
|
||||||
self.get_validator_index(pubkey)?
|
self.get_validator_index(pubkey)?
|
||||||
.ok_or(Error::PubkeyCacheInconsistent)
|
.ok_or(Error::PubkeyCacheInconsistent)?,
|
||||||
})
|
)
|
||||||
.collect()
|
}
|
||||||
|
Ok(indices)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute the sync committee indices for the next sync committee.
|
/// Compute the sync committee indices for the next sync committee.
|
||||||
|
Loading…
Reference in New Issue
Block a user