Skip to content

Commit b201842

Browse files
committed
simplify lindex
1 parent a0241ba commit b201842

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,25 +517,14 @@ impl QuickList {
517517
}
518518

519519
let mut current_index = 0;
520-
521-
// Iterate through nodes to find the requested index
522520
for node in &mut self.nodes {
523-
let node_len = node.entry_count;
524-
if current_index + node_len <= index {
525-
// This node is before our index, skip it
526-
current_index += node_len;
527-
continue;
528-
}
529-
530-
// Decompress the node and read its entries
531-
node.ensure_decompressed(&self.fill_factor);
532-
if let NodeData::Uncompressed(ziplist) = &node.data {
533-
let entries = ziplist.to_vec();
534-
if let Some(entry) = entries.get(index - current_index) {
535-
return Some(entry.clone());
521+
if current_index + node.entry_count > index {
522+
node.ensure_decompressed(&self.fill_factor);
523+
if let NodeData::Uncompressed(ziplist) = &node.data {
524+
return ziplist.to_vec().get(index - current_index).cloned();
536525
}
537526
}
538-
break; // No need to check further nodes
527+
current_index += node.entry_count;
539528
}
540529
None
541530
}

0 commit comments

Comments
 (0)