From acf5040eb07aa2c99a8ef563d5726a26f49e0afb Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Tue, 28 Feb 2023 06:57:28 +0000 Subject: [PATCH] Simplify the code slightly --- primitives/state-machine/src/trie_backend.rs | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/primitives/state-machine/src/trie_backend.rs b/primitives/state-machine/src/trie_backend.rs index 187267d048a47..ce16fe2ee114b 100644 --- a/primitives/state-machine/src/trie_backend.rs +++ b/primitives/state-machine/src/trie_backend.rs @@ -309,17 +309,16 @@ where } fn next_storage_key(&self, key: &[u8]) -> Result, Self::Error> { - let (is_cached, mut cache) = access_cache(&self.next_storage_key_cache, |cache_cell| { - cache_cell - .take() - .map(|cache| (true, cache)) - .unwrap_or_else(|| (false, Default::default())) - }); - - if !is_cached || cache.last_key != key { - let args = - IterArgs { start_at: Some(key), start_at_exclusive: true, ..IterArgs::default() }; - cache.iter = self.raw_iter(args)? + let (is_cached, mut cache) = access_cache(&self.next_storage_key_cache, Option::take) + .map(|cache| (cache.last_key == key, cache)) + .unwrap_or_default(); + + if !is_cached { + cache.iter = self.raw_iter(IterArgs { + start_at: Some(key), + start_at_exclusive: true, + ..IterArgs::default() + })? }; let next_key = match cache.iter.next_key(self) {