Use Vec::with_capacity() to avoid reallocations with repeated push()'s (#34242)

The length of tx_cells is known before the loop that populates it, so we
can appropriately allocate the Vec immediatley to avoid any
reallocations.
This commit is contained in:
steviez 2023-11-28 11:26:47 -06:00 committed by GitHub
parent 32c7acbf74
commit 4d2018fc6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -885,7 +885,7 @@ impl LedgerStorage {
);
let mut by_addr: HashMap<&Pubkey, Vec<TransactionByAddrInfo>> = HashMap::new();
let mut tx_cells = vec![];
let mut tx_cells = Vec::with_capacity(confirmed_block.transactions.len());
for (index, transaction_with_meta) in confirmed_block.transactions.iter().enumerate() {
let VersionedTransactionWithStatusMeta { meta, transaction } = transaction_with_meta;
let err = meta.status.clone().err();