Skip to content

Commit

Permalink
Add backRc optimizing in memdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Jan 19, 2023
1 parent 69235ca commit a6d2683
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/phala-trie-storage/src/memdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ impl<H, KF, T> MemoryDB<H, KF, T>
}

entry.get_mut().1 += rc;
if entry.get().1 == 0 {
_ = entry.remove();
}
},
Entry::Vacant(entry) => {
entry.insert((value, rc));
Expand Down Expand Up @@ -354,6 +357,9 @@ impl<H, KF, T> PlainDB<H::Out, T> for MemoryDB<H, KF, T>
*old_value = value;
}
*rc += 1;
if *rc == 0 {
_ = entry.remove();
}
},
Entry::Vacant(entry) => {
entry.insert((value, 1));
Expand All @@ -366,6 +372,9 @@ impl<H, KF, T> PlainDB<H::Out, T> for MemoryDB<H, KF, T>
Entry::Occupied(mut entry) => {
let &mut (_, ref mut rc) = entry.get_mut();
*rc -= 1;
if *rc == 0 {
_ = entry.remove();
}
},
Entry::Vacant(entry) => {
let value = T::default();
Expand Down Expand Up @@ -433,6 +442,9 @@ impl<H, KF, T> HashDB<H, T> for MemoryDB<H, KF, T>
*old_value = value;
}
*rc += 1;
if *rc == 0 {
_ = entry.remove();
}
},
Entry::Vacant(entry) => {
entry.insert((value, 1));
Expand Down Expand Up @@ -460,6 +472,9 @@ impl<H, KF, T> HashDB<H, T> for MemoryDB<H, KF, T>
Entry::Occupied(mut entry) => {
let &mut (_, ref mut rc) = entry.get_mut();
*rc -= 1;
if *rc == 0 {
_ = entry.remove();
}
},
Entry::Vacant(entry) => {
let value = T::default();
Expand Down

0 comments on commit a6d2683

Please sign in to comment.