Skip to content

Commit 6b7fab8

Browse files
simplify trim_chain
1 parent 094c8ee commit 6b7fab8

1 file changed

Lines changed: 2 additions & 38 deletions

File tree

storage/src/qmdb/current/batch.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -783,53 +783,17 @@ impl<const N: usize> BitmapBatch<N> {
783783
/// replaced by a direct reference to the committed bitmap. Since `apply_batch` commits
784784
/// contiguous prefixes, committed `Layer`s are always at the bottom of the chain.
785785
fn trim_committed(&self) -> Self {
786-
// Fast path: if already Base, nothing to do
787-
if let Self::Base(_) = self {
788-
return self.clone();
789-
}
790-
791786
let shared = self.shared();
792787
let committed = shared.read().len();
793-
788+
let mut kept = Vec::new();
794789
let mut current = self;
795-
let mut uncommitted = 0;
796790
while let Self::Layer(layer) = current {
797791
if layer.overlay.len <= committed {
798792
break;
799793
}
800-
uncommitted += 1;
794+
kept.push(Arc::clone(&layer.overlay));
801795
current = &layer.parent;
802796
}
803-
804-
// Top layer is already committed
805-
if uncommitted == 0 {
806-
return Self::Base(Arc::clone(shared));
807-
}
808-
809-
// No layer is committed; keep the whole chain
810-
if let Self::Base(_) = current {
811-
return self.clone();
812-
}
813-
814-
// Fast path for exactly 1 uncommitted layer (common in chained growth)
815-
if uncommitted == 1 {
816-
if let Self::Layer(layer) = self {
817-
return Self::Layer(Arc::new(BitmapBatchLayer {
818-
parent: Self::Base(Arc::clone(shared)),
819-
overlay: Arc::clone(&layer.overlay),
820-
}));
821-
}
822-
}
823-
824-
let mut kept = Vec::with_capacity(uncommitted);
825-
current = self;
826-
for _ in 0..uncommitted {
827-
if let Self::Layer(layer) = current {
828-
kept.push(Arc::clone(&layer.overlay));
829-
current = &layer.parent;
830-
}
831-
}
832-
833797
let mut result = Self::Base(Arc::clone(shared));
834798
for overlay in kept.into_iter().rev() {
835799
result = Self::Layer(Arc::new(BitmapBatchLayer {

0 commit comments

Comments
 (0)