From e97041f7d0e89dc352552265bf39f9b68963c631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 25 Sep 2024 15:55:52 +0200 Subject: [PATCH] Replace the Lru free list by a simple increment --- milli/src/update/new/extract/lru.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/milli/src/update/new/extract/lru.rs b/milli/src/update/new/extract/lru.rs index cfec6e157..8a35cc440 100644 --- a/milli/src/update/new/extract/lru.rs +++ b/milli/src/update/new/extract/lru.rs @@ -121,14 +121,8 @@ struct FixedSizeListNode { #[derive(Debug)] struct FixedSizeList { nodes: Box<[Option>]>, - // An un-ordered set of indices that are not in use in `nodes`. - // All `None` entries in `nodes` _must_ be listed in `free`. - // A `Vec` was choosen in order to have O(1) complexity - // for pop and avoid having to go through `nodes` in order to - // to find a free place. - // TODO remove the free list as it is always growing: - // we cannot remove entries from the map. - free: Vec, + /// The next None in the nodes. + next_free: usize, // TODO Also, we probably do not need one of the front and back cursors. front: usize, back: usize, @@ -138,7 +132,7 @@ impl FixedSizeList { fn new(capacity: usize) -> Self { Self { nodes: repeat_with(|| None).take(capacity).collect::>().into_boxed_slice(), - free: (0..capacity).collect(), + next_free: 0, front: usize::MAX, back: usize::MAX, } @@ -151,7 +145,7 @@ impl FixedSizeList { #[inline] fn len(&self) -> usize { - self.nodes.len() - self.free.len() + self.nodes.len() - self.next_free } #[inline] @@ -171,7 +165,12 @@ impl FixedSizeList { #[inline] fn next(&mut self) -> Option { - self.free.pop() + if self.is_full() { + None + } else { + self.next_free += 1; + Some(self.next_free) + } } #[inline]