From c1045842f59480a61c856a1944aaebc8fd8b1bcc Mon Sep 17 00:00:00 2001 From: Jeremy Rubin Date: Wed, 6 Feb 2019 14:37:19 -0800 Subject: [PATCH] refactor: use less memory in verifier_cache by storing zero-sized type instead of bool --- core/src/core/verifier_cache.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/src/core/verifier_cache.rs b/core/src/core/verifier_cache.rs index 5e5dc2948f..1f1738ff19 100644 --- a/core/src/core/verifier_cache.rs +++ b/core/src/core/verifier_cache.rs @@ -41,8 +41,8 @@ pub trait VerifierCache: Sync + Send { /// Caches tx kernels by kernel hash. /// Caches outputs by output rangeproof hash (rangeproofs are committed to separately). pub struct LruVerifierCache { - kernel_sig_verification_cache: LruCache, - rangeproof_verification_cache: LruCache, + kernel_sig_verification_cache: LruCache, + rangeproof_verification_cache: LruCache, } impl LruVerifierCache { @@ -60,12 +60,7 @@ impl VerifierCache for LruVerifierCache { fn filter_kernel_sig_unverified(&mut self, kernels: &[TxKernel]) -> Vec { let res = kernels .iter() - .filter(|x| { - !*self - .kernel_sig_verification_cache - .get_mut(&x.hash()) - .unwrap_or(&mut false) - }) + .filter(|x| !self.kernel_sig_verification_cache.contains_key(&x.hash())) .cloned() .collect::>(); trace!( @@ -80,10 +75,9 @@ impl VerifierCache for LruVerifierCache { let res = outputs .iter() .filter(|x| { - !*self + !self .rangeproof_verification_cache - .get_mut(&x.proof.hash()) - .unwrap_or(&mut false) + .contains_key(&x.proof.hash()) }) .cloned() .collect::>(); @@ -97,14 +91,14 @@ impl VerifierCache for LruVerifierCache { fn add_kernel_sig_verified(&mut self, kernels: Vec) { for k in kernels { - self.kernel_sig_verification_cache.insert(k.hash(), true); + self.kernel_sig_verification_cache.insert(k.hash(), ()); } } fn add_rangeproof_verified(&mut self, outputs: Vec) { for o in outputs { self.rangeproof_verification_cache - .insert(o.proof.hash(), true); + .insert(o.proof.hash(), ()); } } }