Skip to content

Commit 1033c74

Browse files
authored
Rollup merge of #74874 - ssomers:btree_cleanup_8, r=Mark-Simulacrum
BTreeMap: define forget_type only when relevant Similar to `forget_node_type` for handles. No effect on generated code, apart maybe from the superfluous calls that might not have been optimized away. r? @Mark-Simulacrum
2 parents 5323b9f + 240ef70 commit 1033c74

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::E
1919
Ok(internal_kv) => return Ok(internal_kv),
2020
Err(last_edge) => match last_edge.into_node().ascend() {
2121
Ok(parent_edge) => parent_edge.forget_node_type(),
22-
Err(root) => return Err(root.forget_type()),
22+
Err(root) => return Err(root),
2323
},
2424
}
2525
}
@@ -40,7 +40,7 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::E
4040
Ok(internal_kv) => return Ok(internal_kv),
4141
Err(last_edge) => match last_edge.into_node().ascend() {
4242
Ok(parent_edge) => parent_edge.forget_node_type(),
43-
Err(root) => return Err(root.forget_type()),
43+
Err(root) => return Err(root),
4444
},
4545
}
4646
}

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,6 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
307307
self.height
308308
}
309309

310-
/// Removes any static information about whether this node is a `Leaf` or an
311-
/// `Internal` node.
312-
pub fn forget_type(self) -> NodeRef<BorrowType, K, V, marker::LeafOrInternal> {
313-
NodeRef { height: self.height, node: self.node, root: self.root, _marker: PhantomData }
314-
}
315-
316310
/// Temporarily takes out another, immutable reference to the same node.
317311
fn reborrow(&self) -> NodeRef<marker::Immut<'_>, K, V, Type> {
318312
NodeRef { height: self.height, node: self.node, root: self.root, _marker: PhantomData }
@@ -1357,6 +1351,20 @@ unsafe fn move_edges<K, V>(
13571351
}
13581352
}
13591353

1354+
impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Leaf> {
1355+
/// Removes any static information asserting that this node is a `Leaf` node.
1356+
pub fn forget_type(self) -> NodeRef<BorrowType, K, V, marker::LeafOrInternal> {
1357+
NodeRef { height: self.height, node: self.node, root: self.root, _marker: PhantomData }
1358+
}
1359+
}
1360+
1361+
impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Internal> {
1362+
/// Removes any static information asserting that this node is an `Internal` node.
1363+
pub fn forget_type(self) -> NodeRef<BorrowType, K, V, marker::LeafOrInternal> {
1364+
NodeRef { height: self.height, node: self.node, root: self.root, _marker: PhantomData }
1365+
}
1366+
}
1367+
13601368
impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge> {
13611369
pub fn forget_node_type(
13621370
self,

0 commit comments

Comments
 (0)