Avoid cloning clean stuff (#2173)
This commit is contained in:
parent
33084aaa07
commit
52a69d19e6
@ -410,10 +410,27 @@ impl fmt::Debug for State {
|
||||
|
||||
impl Clone for State {
|
||||
fn clone(&self) -> State {
|
||||
let cache = {
|
||||
let mut cache = HashMap::new();
|
||||
for (key, val) in self.cache.borrow().iter() {
|
||||
let key = key.clone();
|
||||
match *val {
|
||||
Some(ref acc) if acc.is_dirty() => {
|
||||
cache.insert(key, Some(acc.clone()));
|
||||
},
|
||||
None => {
|
||||
cache.insert(key, None);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
cache
|
||||
};
|
||||
|
||||
State {
|
||||
db: self.db.boxed_clone(),
|
||||
root: self.root.clone(),
|
||||
cache: RefCell::new(self.cache.borrow().clone()),
|
||||
cache: RefCell::new(cache),
|
||||
snapshots: RefCell::new(self.snapshots.borrow().clone()),
|
||||
account_start_nonce: self.account_start_nonce.clone(),
|
||||
trie_factory: self.trie_factory.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user