From e32f10f940e4f257591eb40430ba8a206696f393 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 30 Jun 2021 20:48:57 -0700 Subject: [PATCH] [spv-out] recyclable: Remove capacity reduction code. --- src/back/spv/recyclable.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/back/spv/recyclable.rs b/src/back/spv/recyclable.rs index 54ac912158..c1b7fdcc66 100644 --- a/src/back/spv/recyclable.rs +++ b/src/back/spv/recyclable.rs @@ -29,46 +29,16 @@ pub trait Recyclable { // Stock values for various collections. -/// Maximum extra capacity that a recycled vector is allowed to have. If the -/// actual capacity is larger, we re-allocate the vector storage with lower -/// capacity. -const MAX_EXTRA_CAPACITY_PERCENT: usize = 200; - -/// Minimum extra capacity to keep when re-allocating the vector storage. -const MIN_EXTRA_CAPACITY_PERCENT: usize = 20; - -/// Minimum sensible length to consider for re-allocation. -const MIN_LENGTH: usize = 16; - impl Recyclable for Vec { fn recycle(mut self) -> Self { - let extra_capacity = (self.capacity() - self.len()) * 100 / self.len().max(MIN_LENGTH); - - if extra_capacity > MAX_EXTRA_CAPACITY_PERCENT { - //TODO: use `shrink_to` when it's stable - self = Vec::with_capacity(self.len() + self.len() * MIN_EXTRA_CAPACITY_PERCENT / 100); - } else { - self.clear(); - } - + self.clear(); self } } impl Recyclable for std::collections::HashMap { fn recycle(mut self) -> Self { - let extra_capacity = (self.capacity() - self.len()) * 100 / self.len().max(MIN_LENGTH); - - if extra_capacity > MAX_EXTRA_CAPACITY_PERCENT { - //TODO: use `shrink_to` when it's stable - self = Self::with_capacity_and_hasher( - self.len() + self.len() * MIN_EXTRA_CAPACITY_PERCENT / 100, - self.hasher().clone(), - ); - } else { - self.clear(); - } - + self.clear(); self } }