From 871e0a917a2c0fe3b95ad36c5674eef1ff9f381d Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 2 Sep 2024 15:55:20 -0400 Subject: [PATCH] use hash_map::Entry API to simplify answer_has_sent_return() --- capnp-rpc/src/rpc.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index d9a708d03..ed18a52dc 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -1144,21 +1144,16 @@ impl ConnectionState { } fn answer_has_sent_return(&self, id: AnswerId, result_exports: Vec) { - 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; } }