Skip to content

Commit 0f91df9

Browse files
committed
slight improvement on existing implementation
1 parent b201842 commit 0f91df9

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

duva/src/domains/caches/cache_objects/types/quicklist.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ impl QuickList {
294294
}
295295

296296
let max_bytes = kb * 1024;
297+
let merge_threshold = max_bytes / 4;
297298

298299
let should_merge = {
299300
let node = &self.nodes[index];
300301
let next = &self.nodes[index + 1];
301-
let merge_threshold = max_bytes / 4;
302302

303303
(node.entry_count > 0 && next.entry_count > 0)
304304
&& (node.byte_size() < merge_threshold || next.byte_size() < merge_threshold)
@@ -408,10 +408,13 @@ impl QuickList {
408408
pub fn compress(&mut self) {
409409
let node_count = self.nodes.len();
410410
if self.compress_depth > 0 && node_count > self.compress_depth * 2 {
411-
for i in self.compress_depth..(node_count - self.compress_depth) {
412-
if let Some(node) = self.nodes.get_mut(i) {
413-
node.try_compress();
414-
}
411+
for node in self
412+
.nodes
413+
.iter_mut()
414+
.skip(self.compress_depth)
415+
.take(node_count - self.compress_depth * 2)
416+
{
417+
node.try_compress();
415418
}
416419
}
417420
}

0 commit comments

Comments
 (0)