Skip to content

Commit

Permalink
use hash_map::Entry API to simplify answer_has_sent_return()
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 2, 2024
1 parent 1b5d922 commit 871e0a9
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,21 +1144,16 @@ impl<VatId> ConnectionState<VatId> {
}

fn answer_has_sent_return(&self, id: AnswerId, result_exports: Vec<ExportId>) {
let mut erase = false;
let answers_slots = &mut self.answers.borrow_mut().slots;
if let Some(a) = answers_slots.get_mut(&id) {
a.return_has_been_sent = true;
if a.received_finish.get() {
erase = true;
} else {
a.result_exports = result_exports;
}
} else {
let hash_map::Entry::Occupied(mut entry) = answers_slots.entry(id) else {
unreachable!()
}

if erase {
answers_slots.remove(&id);
};
let a = entry.get_mut();
a.return_has_been_sent = true;
if a.received_finish.get() {
entry.remove();
} else {
a.result_exports = result_exports;
}
}

Expand Down

0 comments on commit 871e0a9

Please sign in to comment.