Skip to content

Commit

Permalink
Use Vec::with_capacity in certain places (from PR #1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplOfAnImpl committed Nov 14, 2024
1 parent 2b99a07 commit a4243a7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> {
.await
.map_err(|e| ApiServerStorageError::LowLevelStorageError(e.to_string()))?;

let mut transaction_ids = vec![];
let mut transaction_ids = Vec::with_capacity(rows.len());

for row in &rows {
let transaction_id: Vec<u8> = row.get(0);
Expand Down
2 changes: 1 addition & 1 deletion chainstate/src/detail/median_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod test {
initial_prev: Id<GenBlock>,
initial_time: BlockTimestampInternalType,
) -> Vec<Block> {
let mut res = vec![];
let mut res = Vec::with_capacity(count);
let mut prev = initial_prev;
let mut time = initial_time;
for _ in 0..count {
Expand Down
4 changes: 2 additions & 2 deletions chainstate/test-framework/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl TestFramework {
) -> Result<Vec<Id<GenBlock>>, ChainstateError> {
let mut prev_block_id = *parent_block;
let result = || -> Result<Vec<Id<GenBlock>>, ChainstateError> {
let mut ids = Vec::new();
let mut ids = Vec::with_capacity(blocks_count);
for _ in 0..blocks_count {
let block = self
.make_block_builder()
Expand Down Expand Up @@ -251,7 +251,7 @@ impl TestFramework {
) -> Result<Vec<Id<GenBlock>>, ChainstateError> {
let mut prev_block_id = *parent_block;
let result = || -> Result<Vec<Id<GenBlock>>, ChainstateError> {
let mut ids = Vec::new();
let mut ids = Vec::with_capacity(blocks_count);
let target_block_time = self.chain_config().target_block_spacing();
for _ in 0..blocks_count {
self.progress_time_seconds_since_epoch(target_block_time.as_secs());
Expand Down
2 changes: 1 addition & 1 deletion test-rpc-functions/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl RpcTestFunctionsRpcServer for super::RpcTestFunctionsHandle {
let coin_decimal_factor = 10u128.pow(coin_decimals as u32);
let mut amount_to_spend = (amount_to_spend as u128) * coin_decimal_factor;
let fee_per_tx = (fee_per_tx as u128) * coin_decimal_factor;
let mut transactions = vec![];
let mut transactions = Vec::with_capacity(num_transactions as usize);
for _ in 0..num_transactions {
let inputs =
vec![TxInput::from_utxo(OutPointSourceId::Transaction(input_tx_id), input_idx)];
Expand Down

0 comments on commit a4243a7

Please sign in to comment.