diff --git a/core/src/caching/bounded/fifo/fifo_cache.rs b/core/src/caching/bounded/fifo/fifo_cache.rs index e73fce53c0b28b79e8eab27e9ccac2f7725b2247..60cb5b00d9949fa97e189e0cba55186f3e9bd5f8 100644 --- a/core/src/caching/bounded/fifo/fifo_cache.rs +++ b/core/src/caching/bounded/fifo/fifo_cache.rs @@ -44,7 +44,7 @@ impl<K, V> FifoCache<K, V> { assert!(tolerance > 0.0); Self { max_capacity, - items: VecDeque::new(), + items: VecDeque::with_capacity(max_capacity), tolerance, } } diff --git a/core/src/caching/bounded/lru/lru_cache.rs b/core/src/caching/bounded/lru/lru_cache.rs index 037ad92001cb075dc91cd12bf03c4810e720a3ee..b60b5af9ef41967b3de06fe7b10878fd9c4f6eda 100644 --- a/core/src/caching/bounded/lru/lru_cache.rs +++ b/core/src/caching/bounded/lru/lru_cache.rs @@ -72,7 +72,7 @@ where } fn insert(&mut self, key: K, value: V) { - if self.len() == self.max_capacity { + if self.len() >= self.max_capacity { if let Some(tail) = self.list.remove_tail() { self.map.remove(&tail.borrow().key); } @@ -93,7 +93,7 @@ impl<K, V> LRUCache<K, V> { assert!(tolerance > 0.0); Self { max_capacity, - map: HashMap::new(), + map: HashMap::with_capacity(max_capacity), list: DoublyLinkedList::new(), tolerance, }