Skip to content

Commit

Permalink
dev: with_capacity for HashMap (paradigmxyz#7246)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored and Ruteri committed Apr 17, 2024
1 parent e892ba4 commit 733ef23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 8 additions & 5 deletions crates/blockchain-tree/src/blockchain_tree.rs
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions crates/node-core/src/init.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 733ef23

Please sign in to comment.