Skip to content

Commit 871e0a9

Browse files
committed
use hash_map::Entry API to simplify answer_has_sent_return()
1 parent 1b5d922 commit 871e0a9

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

capnp-rpc/src/rpc.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,21 +1144,16 @@ impl<VatId> ConnectionState<VatId> {
11441144
}
11451145

11461146
fn answer_has_sent_return(&self, id: AnswerId, result_exports: Vec<ExportId>) {
1147-
let mut erase = false;
11481147
let answers_slots = &mut self.answers.borrow_mut().slots;
1149-
if let Some(a) = answers_slots.get_mut(&id) {
1150-
a.return_has_been_sent = true;
1151-
if a.received_finish.get() {
1152-
erase = true;
1153-
} else {
1154-
a.result_exports = result_exports;
1155-
}
1156-
} else {
1148+
let hash_map::Entry::Occupied(mut entry) = answers_slots.entry(id) else {
11571149
unreachable!()
1158-
}
1159-
1160-
if erase {
1161-
answers_slots.remove(&id);
1150+
};
1151+
let a = entry.get_mut();
1152+
a.return_has_been_sent = true;
1153+
if a.received_finish.get() {
1154+
entry.remove();
1155+
} else {
1156+
a.result_exports = result_exports;
11621157
}
11631158
}
11641159

0 commit comments

Comments
 (0)