Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Avoid cloning clean stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Sep 19, 2016
1 parent 2a82fa0 commit a475d39
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ethcore/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a475d39

Please sign in to comment.