Skip to content

Commit

Permalink
chore: avoid unnecessary cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19-cw committed May 24, 2024
1 parent 58f13fa commit 8230b3a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/eth/storage/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,19 @@ impl RocksStorageState {

/// Updates the in-memory state with changes from transaction execution
pub fn update_state_with_execution_changes(&self, changes: &[ExecutionAccountChanges], block_number: BlockNumber, batch: &mut WriteBatch) {
// Directly capture the fields needed by each future from `self`
let accounts = self.accounts.clone();
let accounts_history = self.accounts_history.clone();
let account_slots = self.account_slots.clone();
let account_slots_history = self.account_slots_history.clone();

let changes_clone_for_accounts = changes.to_vec(); // Clone changes for accounts future
let changes_clone_for_slots = changes.to_vec(); // Clone changes for slots future

let mut account_changes = Vec::new();
let mut account_history_changes = Vec::new();

for change in changes_clone_for_accounts {
for change in changes {
if change.is_changed() {
let address: AddressRocksdb = change.address.into();
let mut account_info_entry = accounts.entry_or_insert_with(address, AccountRocksdb::default);

if let Some(nonce) = change.nonce.clone().take_modified() {
account_info_entry.nonce = nonce.into();
}
Expand All @@ -389,10 +386,11 @@ impl RocksStorageState {
let mut slot_changes = Vec::new();
let mut slot_history_changes = Vec::new();

for change in changes_clone_for_slots {
let address: AddressRocksdb = change.address.into();
for (slot_index, slot_change) in change.slots.clone() {
if let Some(slot) = slot_change.take_modified() {
for change in changes {
for (slot_index, slot_change) in &change.slots {
if let Some(slot) = slot_change.take_modified_ref() {
let address: AddressRocksdb = change.address.into();
let slot_index = *slot_index;
slot_changes.push(((address, slot_index.into()), slot.value.into()));
slot_history_changes.push(((address, slot_index.into(), block_number.into()), slot.value.into()));
}
Expand Down

0 comments on commit 8230b3a

Please sign in to comment.