@@ -22,11 +22,9 @@ pub fn get_account_mut<'cache>(
22
22
if let Some ( call_frame) = call_frame {
23
23
if !call_frame. backup . contains_key ( address) {
24
24
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 ( ) ) ) ;
28
26
} else {
29
- call_frame. backup . insert ( address. clone ( ) , None ) ;
27
+ call_frame. backup . insert ( * address, None ) ;
30
28
}
31
29
}
32
30
}
@@ -47,15 +45,10 @@ pub fn insert_account(
47
45
48
46
// insert account_option cloned into call_frame backup if not already there
49
47
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 ( ) ) ) ;
59
52
}
60
53
61
54
account_option
@@ -70,13 +63,11 @@ pub fn remove_account(
70
63
71
64
// insert account_option cloned into call_frame backup if not already there
72
65
if let Some ( call_frame) = call_frame {
73
- if !call_frame. backup . contains_key ( & address) {
66
+ if !call_frame. backup . contains_key ( address) {
74
67
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 ( ) ) ) ;
78
69
} else {
79
- call_frame. backup . insert ( address. clone ( ) , None ) ;
70
+ call_frame. backup . insert ( * address, None ) ;
80
71
}
81
72
}
82
73
}
0 commit comments