From 9a7cac1e079363fba3525fc2e0b375392fb83987 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Tue, 20 Mar 2018 18:07:54 -0600 Subject: [PATCH] Use the Entry API to remove the double lookup --- src/accountant.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/accountant.rs b/src/accountant.rs index eb9abb9b5d..aaf206e347 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -13,6 +13,7 @@ use historian::{reserve_signature, Historian}; use recorder::Signal; use std::sync::mpsc::SendError; use std::collections::{HashMap, HashSet}; +use std::collections::hash_map::Entry::Occupied; use std::result; use chrono::prelude::*; @@ -153,20 +154,14 @@ impl Accountant { } fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> { - let actionable = if let Some(plan) = self.pending.get_mut(&tx_sig) { - plan.apply_witness(Witness::Signature(from)); - if plan.is_complete() { - complete_transaction(&mut self.balances, &plan); + if let Occupied(mut e) = self.pending.entry(tx_sig) { + e.get_mut().apply_witness(Witness::Signature(from)); + if e.get().is_complete() { + complete_transaction(&mut self.balances, e.get()); + e.remove_entry(); } - plan.is_complete() - } else { - false }; - if actionable { - self.pending.remove(&tx_sig); - } - Ok(()) }