diff --git a/substrate/core/client/db/src/lib.rs b/substrate/core/client/db/src/lib.rs index 62cc8027c2afe0803f104c53f4faa805fbc2319b..daf0f478892dcfe4d3347f9a6c1cefe7b9dfa20c 100644 --- a/substrate/core/client/db/src/lib.rs +++ b/substrate/core/client/db/src/lib.rs @@ -1048,24 +1048,22 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> { operation.apply_aux(&mut transaction); - let mut meta_updates = Vec::new(); + let mut meta_updates = Vec::with_capacity(operation.finalized_blocks.len()); let mut last_finalized_hash = self.blockchain.meta.read().finalized_hash; - if !operation.finalized_blocks.is_empty() { - for (block, justification) in operation.finalized_blocks { - let block_hash = self.blockchain.expect_block_hash_from_id(&block)?; - let block_header = self.blockchain.expect_header(BlockId::Hash(block_hash))?; + for (block, justification) in operation.finalized_blocks { + let block_hash = self.blockchain.expect_block_hash_from_id(&block)?; + let block_header = self.blockchain.expect_header(BlockId::Hash(block_hash))?; - meta_updates.push(self.finalize_block_with_transaction( - &mut transaction, - &block_hash, - &block_header, - Some(last_finalized_hash), - justification, - &mut finalization_displaced_leaves, - )?); - last_finalized_hash = block_hash; - } + meta_updates.push(self.finalize_block_with_transaction( + &mut transaction, + &block_hash, + &block_header, + Some(last_finalized_hash), + justification, + &mut finalization_displaced_leaves, + )?); + last_finalized_hash = block_hash; } let imported = if let Some(pending_block) = operation.pending_block { diff --git a/substrate/core/phragmen/benches/phragmen.rs b/substrate/core/phragmen/benches/phragmen.rs index fec849ab9354708e945dfe2b704ab2e07b6531b0..b73811b33fa55065e44e71a9a269e8db7d1b1088 100644 --- a/substrate/core/phragmen/benches/phragmen.rs +++ b/substrate/core/phragmen/benches/phragmen.rs @@ -61,8 +61,7 @@ fn do_phragmen( // prefix to distinguish the validator and nominator account ranges. let np = 10_000; - let mut candidates = vec![]; - let mut voters = vec![]; + let mut candidates = Vec::with_capacity(num_vals as usize); let mut slashable_balance_of: BTreeMap<AccountId, Balance> = BTreeMap::new(); (1 ..= num_vals) @@ -71,6 +70,7 @@ fn do_phragmen( slashable_balance_of.insert(acc, STAKE + rr(10, 50)); }); + let mut voters = Vec::with_capacity(num_noms as usize); (np ..= (np + num_noms)) .for_each(|acc| { let mut stashes_to_vote = candidates.clone(); diff --git a/substrate/core/sr-io/without_std.rs b/substrate/core/sr-io/without_std.rs index ad5ed77d70b0d8e3d29e9bebc87956b7d9b57eb2..95087b0c481d939dfff90c0fabb148e872d52e20 100644 --- a/substrate/core/sr-io/without_std.rs +++ b/substrate/core/sr-io/without_std.rs @@ -737,8 +737,8 @@ impl StorageApi for () { } fn blake2_256_ordered_trie_root(input: Vec<Vec<u8>>) -> H256 { - let mut values = Vec::new(); - let mut lengths = Vec::new(); + let mut values = Vec::with_capacity(input.len()); + let mut lengths = Vec::with_capacity(input.len()); for v in input { values.extend_from_slice(&v); lengths.push((v.len() as u32).to_le());