avoid cloning of Agreement::received_term

This commit is contained in:
Vladimir Komendantskiy 2018-07-26 17:55:21 +01:00
parent 08d6abf6b4
commit 638cde3d71
1 changed files with 6 additions and 1 deletions

View File

@ -505,8 +505,13 @@ impl<NodeUid: Clone + Debug + Ord> Agreement<NodeUid> {
self.estimated = Some(b);
let mut step = self.send_bval(b)?;
for (sender_id, b) in self.received_term.clone() {
// Create a temporary map of received TERM messages to avoid a second mutable access to
// `self`.
let received_term = replace(&mut self.received_term, BTreeMap::new());
for (sender_id, b) in received_term {
step.extend(self.handle_term(&sender_id, b)?);
// Place the TERM message back.
self.received_term.insert(sender_id, b);
if self.terminated {
return Ok(step);
}