Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/database/src/states/bundle_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl BundleBuilder {
reverts_size += account_revert.size_hint();
reverts_map
.entry(block_number)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push((address, account_revert));
}
});
Expand Down Expand Up @@ -618,7 +618,7 @@ impl BundleState {
// database so we can check if plain state was wiped or not.
let mut account_storage_changed = Vec::with_capacity(account.storage.len());

for (key, slot) in account.storage.iter().map(|(k, v)| (*k, *v)) {
for (&key, &slot) in account.storage.iter() {
// If storage was destroyed that means that storage was wiped.
// In that case we need to check if present storage value is different then ZERO.
let destroyed_and_not_zero = was_destroyed && !slot.present_value.is_zero();
Expand Down
3 changes: 2 additions & 1 deletion crates/database/src/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl<DB: Database> State<DB> {
balances: impl IntoIterator<Item = (Address, u128)>,
) -> Result<(), DB::Error> {
// Make transition and update cache state
let mut transitions = Vec::new();
let balances = balances.into_iter();
let mut transitions = Vec::with_capacity(balances.size_hint().0);
for (address, balance) in balances {
if balance == 0 {
continue;
Expand Down
2 changes: 1 addition & 1 deletion crates/inspector/src/count_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl CountInspector {

/// Get the count for a specific opcode.
pub fn get_count(&self, opcode: u8) -> u64 {
self.opcode_counts.get(&opcode).copied().unwrap_or(0)
self.opcode_counts.get(&opcode).copied().unwrap_or_default()
}

/// Get a reference to all opcode counts.
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const SHORT_ADDRESS_CAP: usize = 300;
#[inline]
pub fn short_address(address: &Address) -> Option<usize> {
if address.0[..18].iter().all(|b| *b == 0) {
let short_address = u16::from_be_bytes(address.0[18..].try_into().unwrap()) as usize;
let short_address = u16::from_be_bytes([address.0[18], address.0[19]]) as usize;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting: an address is 20 bytes, so this is equivalent.

Hopefully the compiler can figure it out and avoid the bounds checks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a constant index to an array that is of fixed size, compiler has all the information needed to optimise it

if short_address < SHORT_ADDRESS_CAP {
return Some(short_address);
}
Expand Down
11 changes: 10 additions & 1 deletion crates/state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,55 @@ impl Account {
}

/// Marks the account as self destructed.
#[inline]
pub fn mark_selfdestruct(&mut self) {
self.status |= AccountStatus::SelfDestructed;
}

/// Unmarks the account as self destructed.
#[inline]
pub fn unmark_selfdestruct(&mut self) {
self.status -= AccountStatus::SelfDestructed;
}

/// Is account marked for self destruct.
#[inline]
pub fn is_selfdestructed(&self) -> bool {
self.status.contains(AccountStatus::SelfDestructed)
}

/// Marks the account as touched
#[inline]
pub fn mark_touch(&mut self) {
self.status |= AccountStatus::Touched;
}

/// Unmarks the touch flag.
#[inline]
pub fn unmark_touch(&mut self) {
self.status -= AccountStatus::Touched;
}

/// If account status is marked as touched.
#[inline]
pub fn is_touched(&self) -> bool {
self.status.contains(AccountStatus::Touched)
}

/// Marks the account as newly created.
#[inline]
pub fn mark_created(&mut self) {
self.status |= AccountStatus::Created;
}

/// Unmarks the created flag.
#[inline]
pub fn unmark_created(&mut self) {
self.status -= AccountStatus::Created;
}

/// Marks the account as cold.
#[inline]
pub fn mark_cold(&mut self) {
self.status |= AccountStatus::Cold;
}
Expand Down Expand Up @@ -393,7 +402,7 @@ impl EvmStorageSlot {
pub fn mark_warm_with_transaction_id(&mut self, transaction_id: usize) -> bool {
let same_id = self.transaction_id == transaction_id;
self.transaction_id = transaction_id;
let was_cold = core::mem::replace(&mut self.is_cold, false);
let was_cold = core::mem::take(&mut self.is_cold);

if same_id {
// only if transaction id is same we are returning was_cold.
Expand Down
Loading