Skip to content

Commit 8c331ee

Browse files
authored
Rollup merge of #74686 - ssomers:btree_cleanup_3, r=Mark-Simulacrum
BTreeMap: remove into_slices and its unsafe block A small tweak to make BTreeMap code shorter and less unsafe. r? @Mark-Simulacrum
2 parents e8876ae + c4f4639 commit 8c331ee

File tree

1 file changed

+3
-10
lines changed
  • library/alloc/src/collections/btree

1 file changed

+3
-10
lines changed

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
466466
fn into_val_slice(self) -> &'a [V] {
467467
unsafe { slice::from_raw_parts(MaybeUninit::first_ptr(&self.as_leaf().vals), self.len()) }
468468
}
469-
470-
fn into_slices(self) -> (&'a [K], &'a [V]) {
471-
// SAFETY: equivalent to reborrow() except not requiring Type: 'a
472-
let k = unsafe { ptr::read(&self) };
473-
(k.into_key_slice(), self.into_val_slice())
474-
}
475469
}
476470

477471
impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
@@ -980,10 +974,9 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Internal>, marke
980974

981975
impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Immut<'a>, K, V, NodeType>, marker::KV> {
982976
pub fn into_kv(self) -> (&'a K, &'a V) {
983-
unsafe {
984-
let (keys, vals) = self.node.into_slices();
985-
(keys.get_unchecked(self.idx), vals.get_unchecked(self.idx))
986-
}
977+
let keys = self.node.into_key_slice();
978+
let vals = self.node.into_val_slice();
979+
unsafe { (keys.get_unchecked(self.idx), vals.get_unchecked(self.idx)) }
987980
}
988981
}
989982

0 commit comments

Comments
 (0)