dev: with_capacity for HashMap (#7246)

This commit is contained in:
greged93
2024-03-20 12:10:30 +01:00
committed by GitHub
parent 6801869c0d
commit c1f051a9dd
2 changed files with 12 additions and 8 deletions

View File

@ -930,11 +930,14 @@ impl<DB: Database, EVM: ExecutorFactory> BlockchainTree<DB, EVM> {
if let Some(header) = canonical_header {
info!(target: "blockchain_tree", ?block_hash, "Block is already canonical, ignoring.");
// TODO: this could be fetched from the chainspec first
let td = self.externals.provider_factory.provider()?.header_td(block_hash)?.ok_or(
CanonicalError::from(BlockValidationError::MissingTotalDifficulty {
hash: *block_hash,
}),
)?;
let td =
self.externals.provider_factory.provider()?.header_td(block_hash)?.ok_or_else(
|| {
CanonicalError::from(BlockValidationError::MissingTotalDifficulty {
hash: *block_hash,
})
},
)?;
if !self
.externals
.provider_factory

View File

@ -100,9 +100,10 @@ pub fn insert_genesis_state<DB: Database>(
tx: &<DB as Database>::TXMut,
genesis: &reth_primitives::Genesis,
) -> ProviderResult<()> {
let mut state_init: BundleStateInit = HashMap::new();
let mut reverts_init = HashMap::new();
let mut contracts: HashMap<B256, Bytecode> = HashMap::new();
let capacity = genesis.alloc.len();
let mut state_init: BundleStateInit = HashMap::with_capacity(capacity);
let mut reverts_init = HashMap::with_capacity(capacity);
let mut contracts: HashMap<B256, Bytecode> = HashMap::with_capacity(capacity);
for (address, account) in &genesis.alloc {
let bytecode_hash = if let Some(code) = &account.code {