Skip to content

Commit d39e095

Browse files
authored
Rollup merge of #79297 - ssomers:btree_post_redux, r=Mark-Simulacrum
BTreeMap: swap the names of NodeRef::new and Root::new_leaf #78104 preserved the name of Root::new_leaf to minimize changes, but the resulting names are confusing. r? `@Mark-Simulacrum`
2 parents b54838f + b04abc4 commit d39e095

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<K, V> Root<K, V> {
6767

6868
// Push key-value pair and new right subtree.
6969
let tree_height = open_node.height() - 1;
70-
let mut right_tree = Root::new_leaf();
70+
let mut right_tree = Root::new();
7171
for _ in 0..tree_height {
7272
right_tree.push_internal_level();
7373
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::ops::{Index, RangeBounds};
99
use core::ptr;
1010

1111
use super::borrow::DormantMutRef;
12-
use super::node::{self, marker, ForceResult::*, Handle, NodeRef};
12+
use super::node::{self, marker, ForceResult::*, Handle, NodeRef, Root};
1313
use super::search::{self, SearchResult::*};
1414
use super::unwrap_unchecked;
1515

@@ -128,7 +128,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
128128
/// ```
129129
#[stable(feature = "rust1", since = "1.0.0")]
130130
pub struct BTreeMap<K, V> {
131-
root: Option<node::Root<K, V>>,
131+
root: Option<Root<K, V>>,
132132
length: usize,
133133
}
134134

@@ -145,15 +145,15 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
145145
impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
146146
fn clone(&self) -> BTreeMap<K, V> {
147147
fn clone_subtree<'a, K: Clone, V: Clone>(
148-
node: node::NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
148+
node: NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
149149
) -> BTreeMap<K, V>
150150
where
151151
K: 'a,
152152
V: 'a,
153153
{
154154
match node.force() {
155155
Leaf(leaf) => {
156-
let mut out_tree = BTreeMap { root: Some(node::Root::new_leaf()), length: 0 };
156+
let mut out_tree = BTreeMap { root: Some(Root::new()), length: 0 };
157157

158158
{
159159
let root = out_tree.root.as_mut().unwrap(); // unwrap succeeds because we just wrapped
@@ -198,7 +198,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
198198
(root, length)
199199
};
200200

201-
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
201+
out_node.push(k, v, subroot.unwrap_or_else(Root::new));
202202
out_tree.length += 1 + sublength;
203203
}
204204
}
@@ -1558,7 +1558,7 @@ pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> {
15581558
length: &'a mut usize,
15591559
/// Burried reference to the root field in the borrowed map.
15601560
/// Wrapped in `Option` to allow drop handler to `take` it.
1561-
dormant_root: Option<DormantMutRef<'a, node::Root<K, V>>>,
1561+
dormant_root: Option<DormantMutRef<'a, Root<K, V>>>,
15621562
/// Contains a leaf edge preceding the next element to be returned, or the last leaf edge.
15631563
/// Empty if the map has no root, if iteration went beyond the last leaf edge,
15641564
/// or if a panic occurred in the predicate.
@@ -2160,8 +2160,8 @@ impl<K, V> BTreeMap<K, V> {
21602160

21612161
/// If the root node is the empty (non-allocated) root node, allocate our
21622162
/// own node. Is an associated function to avoid borrowing the entire BTreeMap.
2163-
fn ensure_is_owned(root: &mut Option<node::Root<K, V>>) -> &mut node::Root<K, V> {
2164-
root.get_or_insert_with(node::Root::new_leaf)
2163+
fn ensure_is_owned(root: &mut Option<Root<K, V>>) -> &mut Root<K, V> {
2164+
root.get_or_insert_with(Root::new)
21652165
}
21662166
}
21672167

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ pub type Root<K, V> = NodeRef<marker::Owned, K, V, marker::LeafOrInternal>;
134134

135135
impl<K, V> Root<K, V> {
136136
/// Returns a new owned tree, with its own root node that is initially empty.
137-
pub fn new_leaf() -> Self {
138-
NodeRef::new().forget_type()
137+
pub fn new() -> Self {
138+
NodeRef::new_leaf().forget_type()
139139
}
140140
}
141141

142142
impl<K, V> NodeRef<marker::Owned, K, V, marker::Leaf> {
143-
fn new() -> Self {
143+
fn new_leaf() -> Self {
144144
Self::from_new_leaf(Box::new(unsafe { LeafNode::new() }))
145145
}
146146

library/alloc/src/collections/btree/node/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ fn test_splitpoint() {
7474

7575
#[test]
7676
fn test_partial_cmp_eq() {
77-
let mut root1 = NodeRef::new();
77+
let mut root1 = NodeRef::new_leaf();
7878
let mut leaf1 = root1.borrow_mut();
7979
leaf1.push(1, ());
8080
let mut root1 = root1.forget_type();
8181
root1.push_internal_level();
82-
let root2 = Root::new_leaf();
82+
let root2 = Root::new();
8383
root1.reborrow().assert_back_pointers();
8484
root2.reborrow().assert_back_pointers();
8585

0 commit comments

Comments
 (0)