Use the Entry API to remove the double lookup
This commit is contained in:
@ -13,6 +13,7 @@ use historian::{reserve_signature, Historian};
|
|||||||
use recorder::Signal;
|
use recorder::Signal;
|
||||||
use std::sync::mpsc::SendError;
|
use std::sync::mpsc::SendError;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::collections::hash_map::Entry::Occupied;
|
||||||
use std::result;
|
use std::result;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
@ -153,20 +154,14 @@ impl Accountant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
||||||
let actionable = if let Some(plan) = self.pending.get_mut(&tx_sig) {
|
if let Occupied(mut e) = self.pending.entry(tx_sig) {
|
||||||
plan.apply_witness(Witness::Signature(from));
|
e.get_mut().apply_witness(Witness::Signature(from));
|
||||||
if plan.is_complete() {
|
if e.get().is_complete() {
|
||||||
complete_transaction(&mut self.balances, &plan);
|
complete_transaction(&mut self.balances, e.get());
|
||||||
|
e.remove_entry();
|
||||||
}
|
}
|
||||||
plan.is_complete()
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if actionable {
|
|
||||||
self.pending.remove(&tx_sig);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user