Apply review feedback

This commit is contained in:
Amanieu d'Antras 2020-04-05 14:27:18 +01:00
parent 7365748c0c
commit 51357cf1cd

View File

@ -2728,8 +2728,7 @@ fn remove_kv_tracking(
let mut at_leaf = true; let mut at_leaf = true;
while cur_node.len() < node::MIN_LEN { while cur_node.len() < node::MIN_LEN {
match handle_underfull_node(cur_node) { match handle_underfull_node(cur_node) {
AtRoot(_) => break, AtRoot => break,
EmptyParent(_) => unreachable!(),
Merged(edge, merged_with_left, offset) => { Merged(edge, merged_with_left, offset) => {
// If we merged with our right sibling then our tracked // If we merged with our right sibling then our tracked
// position has not changed. However if we merged with our // position has not changed. However if we merged with our
@ -2740,7 +2739,6 @@ fn remove_kv_tracking(
Leaf(leaf) => leaf, Leaf(leaf) => leaf,
Internal(_) => unreachable!(), Internal(_) => unreachable!(),
}; };
debug_assert!(idx <= node.len());
pos = unsafe { Handle::new_edge(node, idx) }; pos = unsafe { Handle::new_edge(node, idx) };
} }
@ -2754,7 +2752,7 @@ fn remove_kv_tracking(
at_leaf = false; at_leaf = false;
} }
} }
Stole(_, stole_from_left) => { Stole(stole_from_left) => {
// Adjust the tracked position if we stole from a left sibling // Adjust the tracked position if we stole from a left sibling
if stole_from_left && at_leaf { if stole_from_left && at_leaf {
// SAFETY: This is safe since we just added an element to our node. // SAFETY: This is safe since we just added an element to our node.
@ -2781,10 +2779,9 @@ fn remove_kv_tracking(
} }
enum UnderflowResult<'a, K, V> { enum UnderflowResult<'a, K, V> {
AtRoot(NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>), AtRoot,
EmptyParent(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
Merged(Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge>, bool, usize), Merged(Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge>, bool, usize),
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>, bool), Stole(bool),
} }
fn handle_underfull_node<K, V>( fn handle_underfull_node<K, V>(
@ -2792,17 +2789,15 @@ fn handle_underfull_node<K, V>(
) -> UnderflowResult<'_, K, V> { ) -> UnderflowResult<'_, K, V> {
let parent = match node.ascend() { let parent = match node.ascend() {
Ok(parent) => parent, Ok(parent) => parent,
Err(root) => return AtRoot(root), Err(_) => return AtRoot,
}; };
let (is_left, mut handle) = match parent.left_kv() { let (is_left, mut handle) = match parent.left_kv() {
Ok(left) => (true, left), Ok(left) => (true, left),
Err(parent) => match parent.right_kv() { Err(parent) => {
Ok(right) => (false, right), let right = unsafe { unwrap_unchecked(parent.right_kv().ok()) };
Err(parent) => { (false, right)
return EmptyParent(parent.into_node()); }
}
},
}; };
if handle.can_merge() { if handle.can_merge() {
@ -2814,7 +2809,7 @@ fn handle_underfull_node<K, V>(
} else { } else {
handle.steal_right(); handle.steal_right();
} }
Stole(handle.into_node(), is_left) Stole(is_left)
} }
} }