Skip to content

Commit

Permalink
Use Vec::with_capacity() to avoid reallocations with repeated push()'s
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steven Czabaniuk committed Nov 28, 2023
1 parent b741c9c commit 4665324
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion storage-bigtable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4665324

Please sign in to comment.