create some vectors with initial capacities (#3701)

Signed-off-by: Benjamin Coenen <benjamin.coenen@hotmail.com>
This commit is contained in:
Coenen Benjamin
2019-09-27 11:46:53 +02:00
committed by Bastian Köcher
parent 62be947877
commit 53a43e92aa
3 changed files with 17 additions and 19 deletions
+13 -15
View File
@@ -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 {
+2 -2
View File
@@ -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();
+2 -2
View File
@@ -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());