Skip to content

Commit 653dec1

Browse files
authored
chore(std): Add std HashMap,HashSet (#1041)
1 parent 8148063 commit 653dec1

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/primitives/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ once_cell = { version = "1.19", default-features = false, optional = true }
3232
# utility
3333
enumn = "0.1"
3434
derive_more = { version = "0.99", optional = true }
35+
cfg-if = "1"
3536

3637
# optional
37-
serde = { version = "1.0", default-features = false, features = ["derive", "rc"], optional = true }
38+
serde = { version = "1.0", default-features = false, features = [
39+
"derive",
40+
"rc",
41+
], optional = true }
3842

3943
[build-dependencies]
4044
hex = { version = "0.4", default-features = false }

crates/primitives/src/db.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::{Account, AccountInfo, Address, Bytecode, B256, U256};
1+
use crate::{Account, AccountInfo, Address, Bytecode, HashMap, B256, U256};
22
use auto_impl::auto_impl;
3-
use hashbrown::HashMap as Map;
43

54
pub mod components;
65
pub use components::{
@@ -30,7 +29,7 @@ pub trait Database {
3029
#[auto_impl(&mut, Box)]
3130
pub trait DatabaseCommit {
3231
/// Commit changes to the database.
33-
fn commit(&mut self, changes: Map<Address, Account>);
32+
fn commit(&mut self, changes: HashMap<Address, Account>);
3433
}
3534

3635
/// EVM database interface.

crates/primitives/src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub mod result;
2020
pub mod specification;
2121
pub mod state;
2222
pub mod utilities;
23-
2423
pub use alloy_primitives::{
2524
self, address, b256, bytes, fixed_bytes, hex, hex_literal, ruint, uint, Address, Bytes,
2625
FixedBytes, Log, LogData, B256, I256, U256,
@@ -29,7 +28,16 @@ pub use bitvec;
2928
pub use bytecode::*;
3029
pub use constants::*;
3130
pub use env::*;
32-
pub use hashbrown::{hash_map, hash_set, HashMap, HashSet};
31+
32+
cfg_if::cfg_if! {
33+
if #[cfg(std)] {
34+
pub use std::collections::{hash_map, hash_set, HashMap, HashSet};
35+
use hashbrown as _;
36+
} else {
37+
pub use hashbrown::{hash_map, hash_set, HashMap, HashSet};
38+
}
39+
}
40+
3341
#[cfg(feature = "c-kzg")]
3442
pub use kzg::{EnvKzgSettings, KzgSettings};
3543
pub use precompile::*;

crates/primitives/src/state.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::{Address, Bytecode, B256, KECCAK_EMPTY, U256};
1+
use crate::{Address, Bytecode, HashMap, B256, KECCAK_EMPTY, U256};
22
use bitflags::bitflags;
33
use core::hash::{Hash, Hasher};
4-
use hashbrown::HashMap;
54

65
/// EVM State is a mapping from addresses to accounts.
76
pub type State = HashMap<Address, Account>;

crates/revm/src/journaled_state.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,17 @@ impl JournaledState {
446446
) -> Result<SelfDestructResult, DB::Error> {
447447
let (is_cold, target_exists) = self.load_account_exist(target, db)?;
448448

449-
let acc = if address != target {
449+
if address != target {
450450
// Both accounts are loaded before this point, `address` as we execute its contract.
451451
// and `target` at the beginning of the function.
452-
let [acc, target_account] = self.state.get_many_mut([&address, &target]).unwrap();
452+
let acc_balance = self.state.get_mut(&target).unwrap().info.balance;
453+
454+
let target_account = self.state.get_mut(&target).unwrap();
453455
Self::touch_account(self.journal.last_mut().unwrap(), &target, target_account);
454-
target_account.info.balance += acc.info.balance;
455-
acc
456-
} else {
457-
self.state.get_mut(&address).unwrap()
458-
};
456+
target_account.info.balance += acc_balance;
457+
}
459458

459+
let acc = self.state.get_mut(&address).unwrap();
460460
let balance = acc.info.balance;
461461
let previously_destroyed = acc.is_selfdestructed();
462462
let is_cancun_enabled = SpecId::enabled(self.spec, CANCUN);

0 commit comments

Comments
 (0)