Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add backRc optimizing in memdb
  • Loading branch information
kvinwang committed Jan 19, 2023
commit a6d26833f3aaf220e0c9afdc01101751e477d602
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