mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
btree/delete: rightmost_cell_was_dropped logic is not needed since a) if we balance, we seek anyway, and b) if we dont balance, we retreat anyway
This commit is contained in:
@@ -196,7 +196,6 @@ enum DeleteState {
|
||||
post_balancing_seek_key: Option<DeleteSavepoint>,
|
||||
},
|
||||
CheckNeedsBalancing {
|
||||
rightmost_cell_was_dropped: bool,
|
||||
post_balancing_seek_key: Option<DeleteSavepoint>,
|
||||
},
|
||||
WaitForBalancingToComplete {
|
||||
@@ -4348,12 +4347,10 @@ impl BTreeCursor {
|
||||
post_balancing_seek_key,
|
||||
};
|
||||
} else {
|
||||
let is_last_cell = cell_idx == contents.cell_count().saturating_sub(1);
|
||||
drop_cell(contents, cell_idx, self.usable_space() as u16)?;
|
||||
|
||||
let delete_info = self.state.mut_delete_info().unwrap();
|
||||
delete_info.state = DeleteState::CheckNeedsBalancing {
|
||||
rightmost_cell_was_dropped: is_last_cell,
|
||||
post_balancing_seek_key,
|
||||
};
|
||||
}
|
||||
@@ -4454,13 +4451,11 @@ impl BTreeCursor {
|
||||
|
||||
let delete_info = self.state.mut_delete_info().unwrap();
|
||||
delete_info.state = DeleteState::CheckNeedsBalancing {
|
||||
rightmost_cell_was_dropped: false,
|
||||
post_balancing_seek_key,
|
||||
};
|
||||
}
|
||||
|
||||
DeleteState::CheckNeedsBalancing {
|
||||
rightmost_cell_was_dropped,
|
||||
post_balancing_seek_key,
|
||||
} => {
|
||||
let page = self.stack.top();
|
||||
@@ -4472,15 +4467,6 @@ impl BTreeCursor {
|
||||
let needs_balancing = self.stack.has_parent()
|
||||
&& free_space as usize * 3 > self.usable_space() * 2;
|
||||
|
||||
if rightmost_cell_was_dropped {
|
||||
// If we drop a cell in the middle, e.g. our current index is 2 and we drop 'c' from [a,b,c,d,e], then we don't need to retreat index,
|
||||
// because index 2 is still going to be the right place [a,b,D,e]
|
||||
// but:
|
||||
// If we drop the rightmost cell, e.g. our current index is 4 and we drop 'e' from [a,b,c,d,e], then we need to retreat index,
|
||||
// because index 4 is now pointing beyond the last cell [a,b,c,d] _ <-- index 4
|
||||
self.stack.retreat();
|
||||
}
|
||||
|
||||
if needs_balancing {
|
||||
let delete_info = self.state.mut_delete_info().unwrap();
|
||||
if delete_info.balance_write_info.is_none() {
|
||||
|
||||
Reference in New Issue
Block a user