Skip to content

Commit 13dc11b

Browse files
committed
clippy lints
1 parent 4094cc7 commit 13dc11b

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

crates/vm/levm/src/db/cache.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ pub fn get_account_mut<'cache>(
2222
if let Some(call_frame) = call_frame {
2323
if !call_frame.backup.contains_key(address) {
2424
if let Some(account) = account_option.as_ref() {
25-
call_frame
26-
.backup
27-
.insert(address.clone(), Some((*account).clone()));
25+
call_frame.backup.insert(*address, Some((*account).clone()));
2826
} else {
29-
call_frame.backup.insert(address.clone(), None);
27+
call_frame.backup.insert(*address, None);
3028
}
3129
}
3230
}
@@ -47,15 +45,10 @@ pub fn insert_account(
4745

4846
// insert account_option cloned into call_frame backup if not already there
4947
if let Some(call_frame) = call_frame {
50-
if !call_frame.backup.contains_key(&address) {
51-
if let Some(account) = account_option.as_ref() {
52-
call_frame
53-
.backup
54-
.insert(address.clone(), Some((*account).clone()));
55-
} else {
56-
call_frame.backup.insert(address.clone(), None);
57-
}
58-
}
48+
call_frame
49+
.backup
50+
.entry(address)
51+
.or_insert_with(|| account_option.as_ref().map(|account| (*account).clone()));
5952
}
6053

6154
account_option
@@ -70,13 +63,11 @@ pub fn remove_account(
7063

7164
// insert account_option cloned into call_frame backup if not already there
7265
if let Some(call_frame) = call_frame {
73-
if !call_frame.backup.contains_key(&address) {
66+
if !call_frame.backup.contains_key(address) {
7467
if let Some(account) = account_option.as_ref() {
75-
call_frame
76-
.backup
77-
.insert(address.clone(), Some((*account).clone()));
68+
call_frame.backup.insert(*address, Some((*account).clone()));
7869
} else {
79-
call_frame.backup.insert(address.clone(), None);
70+
call_frame.backup.insert(*address, None);
8071
}
8172
}
8273
}

crates/vm/levm/src/opcode_handlers/system.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{
2-
account,
32
call_frame::CallFrame,
43
constants::{CREATE_DEPLOYMENT_FAIL, INIT_CODE_MAX_SIZE, REVERT_FOR_CALL, SUCCESS_FOR_CALL},
54
db::cache,
@@ -734,9 +733,10 @@ impl<'a> VM<'a> {
734733
.push(address_to_word(new_address))?;
735734

736735
for (address, account_opt) in new_call_frame.backup {
737-
if !current_call_frame.backup.contains_key(&address) {
738-
current_call_frame.backup.insert(address, account_opt);
739-
}
736+
current_call_frame
737+
.backup
738+
.entry(address)
739+
.or_insert(account_opt);
740740
}
741741
}
742742
TxResult::Revert(err) => {
@@ -877,9 +877,10 @@ impl<'a> VM<'a> {
877877
TxResult::Success => {
878878
current_call_frame.stack.push(SUCCESS_FOR_CALL)?;
879879
for (address, account_opt) in new_call_frame.backup {
880-
if !current_call_frame.backup.contains_key(&address) {
881-
current_call_frame.backup.insert(address, account_opt);
882-
}
880+
current_call_frame
881+
.backup
882+
.entry(address)
883+
.or_insert(account_opt);
883884
}
884885
}
885886
TxResult::Revert(_) => {

0 commit comments

Comments
 (0)