Skip to content

Commit 1b5d922

Browse files
committed
use hash_map::Entry API to simplify handle_finish()
1 parent d332bb3 commit 1b5d922

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

capnp-rpc/src/rpc.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -771,15 +771,15 @@ impl<VatId> ConnectionState<VatId> {
771771
let mut exports_to_release = Vec::new();
772772
let answer_id = finish.get_question_id();
773773

774-
let mut erase = false;
775774
let answers_slots = &mut connection_state.answers.borrow_mut().slots;
776-
match answers_slots.get_mut(&answer_id) {
777-
None => {
775+
match answers_slots.entry(answer_id) {
776+
hash_map::Entry::Vacant(_) => {
778777
return Err(Error::failed(format!(
779778
"Invalid question ID {answer_id} in Finish message."
780779
)));
781780
}
782-
Some(answer) => {
781+
hash_map::Entry::Occupied(mut entry) => {
782+
let answer = entry.get_mut();
783783
answer.received_finish.set(true);
784784

785785
if finish.get_release_result_caps() {
@@ -791,15 +791,11 @@ impl<VatId> ConnectionState<VatId> {
791791
answer.call_completion_promise.take();
792792

793793
if answer.return_has_been_sent {
794-
erase = true;
794+
entry.remove();
795795
}
796796
}
797797
}
798798

799-
if erase {
800-
answers_slots.remove(&answer_id);
801-
}
802-
803799
connection_state.release_exports(&exports_to_release)?;
804800
Ok(())
805801
}

0 commit comments

Comments
 (0)