Skip to content

Commit a47d3e5

Browse files
authored
chore(primitives): replace HashMap re-exports with alloy_primitives::map (#1805)
* chore(primitives): replace HashMap re-exports with alloy_primitives::map * chore: update methods * chore: update * use default hasher
1 parent 798d08c commit a47d3e5

File tree

21 files changed

+393
-368
lines changed

21 files changed

+393
-368
lines changed

Cargo.lock

Lines changed: 328 additions & 289 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bins/revme/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ inspector = { workspace = true, features = ["std", "serde-json"] }
1818
bytecode = { workspace = true, features = ["std", "parse"] }
1919

2020
hash-db = "0.15"
21-
hex = "0.4"
2221
hashbrown = "0.14"
2322
indicatif = "0.17"
2423
microbench = "0.5"

bins/revme/src/cmd/bench/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use database::{BenchmarkDB, EthereumBenchmarkWiring};
22
use revm::{
33
bytecode::Bytecode,
4-
primitives::{address, bytes, Bytes, TxKind},
4+
primitives::{address, bytes, hex, Bytes, TxKind},
55
Evm,
66
};
77
use std::time::Instant;

bins/revme/src/cmd/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use revm::{
33
bytecode::eof::{self, validate_eof_inner, CodeType, Eof, EofError},
4-
primitives::{Bytes, MAX_INITCODE_SIZE},
4+
primitives::{hex, Bytes, MAX_INITCODE_SIZE},
55
};
66
use std::io;
77

bins/revme/src/cmd/evmrunner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use database::BenchmarkDB;
33
use inspector::{inspector_handle_register, inspectors::TracerEip3155};
44
use revm::{
55
bytecode::{Bytecode, BytecodeDecodeError},
6-
primitives::{address, Address, TxKind},
6+
primitives::{address, hex, Address, TxKind},
77
wiring::EthereumWiring,
88
Database, Evm,
99
};

crates/database/src/in_memory_db.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ impl<ExtDB: Default> Default for CacheDB<ExtDB> {
4141

4242
impl<ExtDB> CacheDB<ExtDB> {
4343
pub fn new(db: ExtDB) -> Self {
44-
let mut contracts = HashMap::new();
44+
let mut contracts = HashMap::default();
4545
contracts.insert(KECCAK_EMPTY, Bytecode::default());
4646
contracts.insert(B256::ZERO, Bytecode::default());
4747
Self {
48-
accounts: HashMap::new(),
48+
accounts: HashMap::default(),
4949
contracts,
5050
logs: Vec::default(),
51-
block_hashes: HashMap::new(),
51+
block_hashes: HashMap::default(),
5252
db,
5353
}
5454
}
@@ -413,7 +413,7 @@ impl Database for BenchmarkDB {
413413
mod tests {
414414
use super::{CacheDB, EmptyDB};
415415
use database_interface::Database;
416-
use primitives::{Address, U256};
416+
use primitives::{Address, HashMap, U256};
417417
use state::AccountInfo;
418418

419419
#[test]
@@ -460,7 +460,7 @@ mod tests {
460460

461461
let mut new_state = CacheDB::new(init_state);
462462
new_state
463-
.replace_account_storage(account, [(key1, value1)].into())
463+
.replace_account_storage(account, HashMap::from_iter([(key1, value1)]))
464464
.unwrap();
465465

466466
assert_eq!(new_state.basic(account).unwrap().unwrap().nonce, nonce);

crates/database/src/states/bundle_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl BundleAccount {
9494
AccountInfoRevert::DeleteIt => {
9595
self.info = None;
9696
if self.original_info.is_none() {
97-
self.storage = HashMap::new();
97+
self.storage = HashMap::default();
9898
return true;
9999
} else {
100100
// set all storage to zero but preserve original values.

crates/database/src/states/bundle_state.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ impl OriginalValuesKnown {
5757
impl Default for BundleBuilder {
5858
fn default() -> Self {
5959
BundleBuilder {
60-
states: HashSet::new(),
61-
state_original: HashMap::new(),
62-
state_present: HashMap::new(),
63-
state_storage: HashMap::new(),
60+
states: HashSet::default(),
61+
state_original: HashMap::default(),
62+
state_present: HashMap::default(),
63+
state_storage: HashMap::default(),
6464
reverts: BTreeSet::new(),
6565
revert_range: 0..=0,
66-
revert_account: HashMap::new(),
67-
revert_storage: HashMap::new(),
68-
contracts: HashMap::new(),
66+
revert_account: HashMap::default(),
67+
revert_storage: HashMap::default(),
68+
contracts: HashMap::default(),
6969
}
7070
}
7171
}
@@ -805,7 +805,7 @@ impl BundleState {
805805
let mut account = BundleAccount::new(
806806
None,
807807
None,
808-
HashMap::new(),
808+
HashMap::default(),
809809
AccountStatus::LoadedNotExisting,
810810
);
811811
if !account.revert(revert_account) {
@@ -920,7 +920,7 @@ mod tests {
920920
code_hash: KECCAK_EMPTY,
921921
code: None,
922922
}),
923-
HashMap::from([
923+
HashMap::from_iter([
924924
(slot1(), (U256::from(0), U256::from(10))),
925925
(slot2(), (U256::from(0), U256::from(15))),
926926
]),
@@ -934,7 +934,7 @@ mod tests {
934934
code_hash: KECCAK_EMPTY,
935935
code: None,
936936
}),
937-
HashMap::from([]),
937+
HashMap::default(),
938938
),
939939
],
940940
vec![vec![
@@ -962,7 +962,7 @@ mod tests {
962962
code_hash: KECCAK_EMPTY,
963963
code: None,
964964
}),
965-
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
965+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
966966
)],
967967
vec![vec![(
968968
account1(),
@@ -992,7 +992,7 @@ mod tests {
992992
)
993993
.state_storage(
994994
account1(),
995-
HashMap::from([(slot1(), (U256::from(0), U256::from(10)))]),
995+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(10)))]),
996996
)
997997
.state_address(account2())
998998
.state_present_account_info(
@@ -1025,7 +1025,7 @@ mod tests {
10251025
)
10261026
.state_storage(
10271027
account1(),
1028-
HashMap::from([(slot1(), (U256::from(0), U256::from(15)))]),
1028+
HashMap::from_iter([(slot1(), (U256::from(0), U256::from(15)))]),
10291029
)
10301030
.revert_address(0, account1())
10311031
.revert_account_info(
@@ -1155,7 +1155,7 @@ mod tests {
11551155
Some(&BundleAccount::new(
11561156
None,
11571157
Some(AccountInfo::default()),
1158-
HashMap::new(),
1158+
HashMap::default(),
11591159
AccountStatus::Changed
11601160
))
11611161
);
@@ -1290,7 +1290,7 @@ mod tests {
12901290
assert!(builder.get_state_storage_mut().is_empty());
12911291
builder
12921292
.get_state_storage_mut()
1293-
.insert(account1(), HashMap::new());
1293+
.insert(account1(), HashMap::default());
12941294
assert!(builder.get_state_storage_mut().contains_key(&account1()));
12951295

12961296
// Test get_reverts_mut

crates/database/src/states/cache_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl CacheAccount {
186186
status: self.status,
187187
previous_info,
188188
previous_status,
189-
storage: HashMap::new(),
189+
storage: HashMap::default(),
190190
storage_was_destroyed: true,
191191
})
192192
}
@@ -259,7 +259,7 @@ impl CacheAccount {
259259
status: self.status,
260260
previous_info,
261261
previous_status,
262-
storage: HashMap::new(),
262+
storage: HashMap::default(),
263263
storage_was_destroyed: false,
264264
},
265265
)

crates/database/src/states/plain_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl From<AccountInfo> for PlainAccount {
8787
fn from(info: AccountInfo) -> Self {
8888
Self {
8989
info,
90-
storage: HashMap::new(),
90+
storage: HashMap::default(),
9191
}
9292
}
9393
}

0 commit comments

Comments
 (0)