From b04abc433ed3477c208dad62e5c3c32d0bb26929 Mon Sep 17 00:00:00 2001 From: Stein Somers Date: Sun, 22 Nov 2020 12:29:48 +0100 Subject: [PATCH] BTreeMap: swap the names of NodeRef::new and Root::new_leaf --- library/alloc/src/collections/btree/append.rs | 2 +- library/alloc/src/collections/btree/map.rs | 16 ++++++++-------- library/alloc/src/collections/btree/node.rs | 6 +++--- .../alloc/src/collections/btree/node/tests.rs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/library/alloc/src/collections/btree/append.rs b/library/alloc/src/collections/btree/append.rs index d3edcd0b87e0f..bd99c4ed2f14e 100644 --- a/library/alloc/src/collections/btree/append.rs +++ b/library/alloc/src/collections/btree/append.rs @@ -67,7 +67,7 @@ impl Root { // Push key-value pair and new right subtree. let tree_height = open_node.height() - 1; - let mut right_tree = Root::new_leaf(); + let mut right_tree = Root::new(); for _ in 0..tree_height { right_tree.push_internal_level(); } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index a9e416875905c..383f4487aff3d 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -9,7 +9,7 @@ use core::ops::{Index, RangeBounds}; use core::ptr; use super::borrow::DormantMutRef; -use super::node::{self, marker, ForceResult::*, Handle, NodeRef}; +use super::node::{self, marker, ForceResult::*, Handle, NodeRef, Root}; use super::search::{self, SearchResult::*}; use super::unwrap_unchecked; @@ -128,7 +128,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct BTreeMap { - root: Option>, + root: Option>, length: usize, } @@ -145,7 +145,7 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap { impl Clone for BTreeMap { fn clone(&self) -> BTreeMap { fn clone_subtree<'a, K: Clone, V: Clone>( - node: node::NodeRef, K, V, marker::LeafOrInternal>, + node: NodeRef, K, V, marker::LeafOrInternal>, ) -> BTreeMap where K: 'a, @@ -153,7 +153,7 @@ impl Clone for BTreeMap { { match node.force() { Leaf(leaf) => { - let mut out_tree = BTreeMap { root: Some(node::Root::new_leaf()), length: 0 }; + let mut out_tree = BTreeMap { root: Some(Root::new()), length: 0 }; { let root = out_tree.root.as_mut().unwrap(); // unwrap succeeds because we just wrapped @@ -198,7 +198,7 @@ impl Clone for BTreeMap { (root, length) }; - out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf)); + out_node.push(k, v, subroot.unwrap_or_else(Root::new)); out_tree.length += 1 + sublength; } } @@ -1558,7 +1558,7 @@ pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> { length: &'a mut usize, /// Burried reference to the root field in the borrowed map. /// Wrapped in `Option` to allow drop handler to `take` it. - dormant_root: Option>>, + dormant_root: Option>>, /// Contains a leaf edge preceding the next element to be returned, or the last leaf edge. /// Empty if the map has no root, if iteration went beyond the last leaf edge, /// or if a panic occurred in the predicate. @@ -2160,8 +2160,8 @@ impl BTreeMap { /// If the root node is the empty (non-allocated) root node, allocate our /// own node. Is an associated function to avoid borrowing the entire BTreeMap. - fn ensure_is_owned(root: &mut Option>) -> &mut node::Root { - root.get_or_insert_with(node::Root::new_leaf) + fn ensure_is_owned(root: &mut Option>) -> &mut Root { + root.get_or_insert_with(Root::new) } } diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index 4658629753da2..e3e555a72de02 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -134,13 +134,13 @@ pub type Root = NodeRef; impl Root { /// Returns a new owned tree, with its own root node that is initially empty. - pub fn new_leaf() -> Self { - NodeRef::new().forget_type() + pub fn new() -> Self { + NodeRef::new_leaf().forget_type() } } impl NodeRef { - fn new() -> Self { + fn new_leaf() -> Self { Self::from_new_leaf(Box::new(unsafe { LeafNode::new() })) } diff --git a/library/alloc/src/collections/btree/node/tests.rs b/library/alloc/src/collections/btree/node/tests.rs index bbf35891b568f..6886962106b02 100644 --- a/library/alloc/src/collections/btree/node/tests.rs +++ b/library/alloc/src/collections/btree/node/tests.rs @@ -74,12 +74,12 @@ fn test_splitpoint() { #[test] fn test_partial_cmp_eq() { - let mut root1 = NodeRef::new(); + let mut root1 = NodeRef::new_leaf(); let mut leaf1 = root1.borrow_mut(); leaf1.push(1, ()); let mut root1 = root1.forget_type(); root1.push_internal_level(); - let root2 = Root::new_leaf(); + let root2 = Root::new(); root1.reborrow().assert_back_pointers(); root2.reborrow().assert_back_pointers();