Skip to content

Commit 51357cf

Browse files
committed
Apply review feedback
1 parent 7365748 commit 51357cf

File tree

1 file changed

+10
-15
lines changed
  • src/liballoc/collections/btree

1 file changed

+10
-15
lines changed

src/liballoc/collections/btree/map.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,8 +2728,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27282728
let mut at_leaf = true;
27292729
while cur_node.len() < node::MIN_LEN {
27302730
match handle_underfull_node(cur_node) {
2731-
AtRoot(_) => break,
2732-
EmptyParent(_) => unreachable!(),
2731+
AtRoot => break,
27332732
Merged(edge, merged_with_left, offset) => {
27342733
// If we merged with our right sibling then our tracked
27352734
// position has not changed. However if we merged with our
@@ -2740,7 +2739,6 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27402739
Leaf(leaf) => leaf,
27412740
Internal(_) => unreachable!(),
27422741
};
2743-
debug_assert!(idx <= node.len());
27442742
pos = unsafe { Handle::new_edge(node, idx) };
27452743
}
27462744

@@ -2754,7 +2752,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27542752
at_leaf = false;
27552753
}
27562754
}
2757-
Stole(_, stole_from_left) => {
2755+
Stole(stole_from_left) => {
27582756
// Adjust the tracked position if we stole from a left sibling
27592757
if stole_from_left && at_leaf {
27602758
// SAFETY: This is safe since we just added an element to our node.
@@ -2781,28 +2779,25 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27812779
}
27822780

27832781
enum UnderflowResult<'a, K, V> {
2784-
AtRoot(NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>),
2785-
EmptyParent(NodeRef<marker::Mut<'a>, K, V, marker::Internal>),
2782+
AtRoot,
27862783
Merged(Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge>, bool, usize),
2787-
Stole(NodeRef<marker::Mut<'a>, K, V, marker::Internal>, bool),
2784+
Stole(bool),
27882785
}
27892786

27902787
fn handle_underfull_node<K, V>(
27912788
node: NodeRef<marker::Mut<'_>, K, V, marker::LeafOrInternal>,
27922789
) -> UnderflowResult<'_, K, V> {
27932790
let parent = match node.ascend() {
27942791
Ok(parent) => parent,
2795-
Err(root) => return AtRoot(root),
2792+
Err(_) => return AtRoot,
27962793
};
27972794

27982795
let (is_left, mut handle) = match parent.left_kv() {
27992796
Ok(left) => (true, left),
2800-
Err(parent) => match parent.right_kv() {
2801-
Ok(right) => (false, right),
2802-
Err(parent) => {
2803-
return EmptyParent(parent.into_node());
2804-
}
2805-
},
2797+
Err(parent) => {
2798+
let right = unsafe { unwrap_unchecked(parent.right_kv().ok()) };
2799+
(false, right)
2800+
}
28062801
};
28072802

28082803
if handle.can_merge() {
@@ -2814,7 +2809,7 @@ fn handle_underfull_node<K, V>(
28142809
} else {
28152810
handle.steal_right();
28162811
}
2817-
Stole(handle.into_node(), is_left)
2812+
Stole(is_left)
28182813
}
28192814
}
28202815

0 commit comments

Comments
 (0)