From 4d2018fc6e85c047266f79c4419ce61f65d97f3b Mon Sep 17 00:00:00 2001 From: steviez Date: Tue, 28 Nov 2023 11:26:47 -0600 Subject: [PATCH] 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. --- storage-bigtable/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage-bigtable/src/lib.rs b/storage-bigtable/src/lib.rs index 0b8ed4d3a..5b9652de9 100644 --- a/storage-bigtable/src/lib.rs +++ b/storage-bigtable/src/lib.rs @@ -885,7 +885,7 @@ impl LedgerStorage { ); let mut by_addr: HashMap<&Pubkey, Vec> = 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();