From 52a69d19e62ea0345b59e22e0644ea1c62a626d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 20 Sep 2016 17:10:26 +0200 Subject: [PATCH] Avoid cloning clean stuff (#2173) --- ethcore/src/state.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index 2c111161188..f20a88882b1 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -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(),