Skip to content

Commit 1794a79

Browse files
committed
Revert all changes of #74762 impacting generated code
1 parent c1c211a commit 1794a79

File tree

1 file changed

+15
-55
lines changed
  • library/alloc/src/collections/btree

1 file changed

+15
-55
lines changed

library/alloc/src/collections/btree/map.rs

+15-55
Original file line numberDiff line numberDiff line change
@@ -1255,11 +1255,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
12551255
}
12561256
pub(super) fn drain_filter_inner(&mut self) -> DrainFilterInner<'_, K, V> {
12571257
let front = self.root.as_mut().map(|r| r.as_mut().first_leaf_edge());
1258-
DrainFilterInner {
1259-
length: &mut self.length,
1260-
cur_leaf_edge: front,
1261-
emptied_internal_root: false,
1262-
}
1258+
DrainFilterInner { length: &mut self.length, cur_leaf_edge: front }
12631259
}
12641260

12651261
/// Calculates the number of elements if it is incorrect.
@@ -1629,7 +1625,6 @@ where
16291625
pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> {
16301626
length: &'a mut usize,
16311627
cur_leaf_edge: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>>,
1632-
emptied_internal_root: bool,
16331628
}
16341629

16351630
#[unstable(feature = "btree_drain_filter", issue = "70530")]
@@ -1670,17 +1665,6 @@ where
16701665
}
16711666
}
16721667

1673-
impl<K, V> Drop for DrainFilterInner<'_, K, V> {
1674-
fn drop(&mut self) {
1675-
if self.emptied_internal_root {
1676-
if let Some(handle) = self.cur_leaf_edge.take() {
1677-
let root = handle.into_node().into_root_mut();
1678-
root.pop_internal_level();
1679-
}
1680-
}
1681-
}
1682-
}
1683-
16841668
impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
16851669
/// Allow Debug implementations to predict the next element.
16861670
pub(super) fn peek(&self) -> Option<(&K, &V)> {
@@ -1697,10 +1681,9 @@ impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
16971681
let (k, v) = kv.kv_mut();
16981682
if pred(k, v) {
16991683
*self.length -= 1;
1700-
let RemoveResult { old_kv, pos, emptied_internal_root } = kv.remove_kv_tracking();
1701-
self.cur_leaf_edge = Some(pos);
1702-
self.emptied_internal_root |= emptied_internal_root;
1703-
return Some(old_kv);
1684+
let (k, v, leaf_edge_location) = kv.remove_kv_tracking();
1685+
self.cur_leaf_edge = Some(leaf_edge_location);
1686+
return Some((k, v));
17041687
}
17051688
self.cur_leaf_edge = Some(kv.next_leaf_edge());
17061689
}
@@ -2668,31 +2651,17 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
26682651
fn remove_kv(self) -> (K, V) {
26692652
*self.length -= 1;
26702653

2671-
let RemoveResult { old_kv, pos, emptied_internal_root } = self.handle.remove_kv_tracking();
2672-
if emptied_internal_root {
2673-
let root = pos.into_node().into_root_mut();
2674-
root.pop_internal_level();
2675-
}
2676-
old_kv
2654+
let (old_key, old_val, _) = self.handle.remove_kv_tracking();
2655+
(old_key, old_val)
26772656
}
26782657
}
26792658

2680-
struct RemoveResult<'a, K, V> {
2681-
// Key and value removed.
2682-
old_kv: (K, V),
2683-
// Unique location at the leaf level that the removed KV lopgically collapsed into.
2684-
pos: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,
2685-
// Whether the remove left behind and empty internal root node, that should be removed
2686-
// using `pop_internal_level`.
2687-
emptied_internal_root: bool,
2688-
}
2689-
26902659
impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV> {
2691-
/// Removes a key/value-pair from the tree, and returns that pair, as well as
2692-
/// the leaf edge corresponding to that former pair. It's possible this leaves
2693-
/// an empty internal root node, which the caller should subsequently pop from
2694-
/// the map holding the tree. The caller should also decrement the map's length.
2695-
fn remove_kv_tracking(self) -> RemoveResult<'a, K, V> {
2660+
/// Removes a key/value-pair from the map, and returns that pair, as well as
2661+
/// the leaf edge corresponding to that former pair.
2662+
fn remove_kv_tracking(
2663+
self,
2664+
) -> (K, V, Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>) {
26962665
let (mut pos, old_key, old_val, was_internal) = match self.force() {
26972666
Leaf(leaf) => {
26982667
let (hole, old_key, old_val) = leaf.remove();
@@ -2721,7 +2690,6 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27212690
};
27222691

27232692
// Handle underflow
2724-
let mut emptied_internal_root = false;
27252693
let mut cur_node = unsafe { ptr::read(&pos).into_node().forget_type() };
27262694
let mut at_leaf = true;
27272695
while cur_node.len() < node::MIN_LEN {
@@ -2743,7 +2711,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27432711
let parent = edge.into_node();
27442712
if parent.len() == 0 {
27452713
// This empty parent must be the root, and should be popped off the tree.
2746-
emptied_internal_root = true;
2714+
parent.into_root_mut().pop_internal_level();
27472715
break;
27482716
} else {
27492717
cur_node = parent.forget_type();
@@ -2770,7 +2738,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInter
27702738
pos = unsafe { unwrap_unchecked(pos.next_kv().ok()).next_leaf_edge() };
27712739
}
27722740

2773-
RemoveResult { old_kv: (old_key, old_val), pos, emptied_internal_root }
2741+
(old_key, old_val, pos)
27742742
}
27752743
}
27762744

@@ -2850,16 +2818,8 @@ fn handle_underfull_node<K, V>(
28502818
let (is_left, mut handle) = match parent.left_kv() {
28512819
Ok(left) => (true, left),
28522820
Err(parent) => {
2853-
match parent.right_kv() {
2854-
Ok(right) => (false, right),
2855-
Err(_) => {
2856-
// The underfull node has an empty parent, so it is the only child
2857-
// of an empty root. It is destined to become the new root, thus
2858-
// allowed to be underfull. The empty parent should be removed later
2859-
// by `pop_internal_level`.
2860-
return AtRoot;
2861-
}
2862-
}
2821+
let right = unsafe { unwrap_unchecked(parent.right_kv().ok()) };
2822+
(false, right)
28632823
}
28642824
};
28652825

0 commit comments

Comments
 (0)