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

Commit

Permalink
Simplify the code slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
koute committed Feb 28, 2023
1 parent 2dc54ae commit acf5040
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions primitives/state-machine/src/trie_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,16 @@ where
}

fn next_storage_key(&self, key: &[u8]) -> Result<Option<StorageKey>, 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) {
Expand Down

0 comments on commit acf5040

Please sign in to comment.