about summary refs log tree commit diff
path: root/src/liballoc/collections/btree/node.rs
diff options
context:
space:
mode:
authorStein Somers <git@steinsomers.be>2020-01-02 12:42:31 +0100
committerStein Somers <git@steinsomers.be>2020-01-09 11:45:32 +0100
commit37b5cca3d58413fafdf40aa231bcc5ababaaa0fe (patch)
tree4fe0670808208d4f466900c40e28365dba9826f6 /src/liballoc/collections/btree/node.rs
parented6468da160bd67a2ce0573427f09a98daff8c07 (diff)
downloadrust-37b5cca3d58413fafdf40aa231bcc5ababaaa0fe.tar.gz
rust-37b5cca3d58413fafdf40aa231bcc5ababaaa0fe.zip
Simplify into_key_slice_mut and document bits and bobs
Diffstat (limited to 'src/liballoc/collections/btree/node.rs')
-rw-r--r--src/liballoc/collections/btree/node.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs
index 260e51d635d..03cb54ebce7 100644
--- a/src/liballoc/collections/btree/node.rs
+++ b/src/liballoc/collections/btree/node.rs
@@ -397,6 +397,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
 
     /// Borrows a view into the values stored in the node.
     /// The caller must ensure that the node is not the shared root.
+    /// This function is not public, so doesn't have to support shared roots like `keys` does.
     fn vals(&self) -> &[V] {
         self.reborrow().into_val_slice()
     }
@@ -514,6 +515,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
     }
 
     /// The caller must ensure that the node is not the shared root.
+    /// This function is not public, so doesn't have to support shared roots like `keys` does.
     fn keys_mut(&mut self) -> &mut [K] {
         unsafe { self.reborrow_mut().into_key_slice_mut() }
     }
@@ -590,19 +592,13 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
     }
 
     fn into_key_slice_mut(mut self) -> &'a mut [K] {
-        // Same as for `into_key_slice` above, we try to avoid a run-time check.
-        if (mem::align_of::<NodeHeader<K, V, K>>() > mem::align_of::<NodeHeader<K, V>>()
-            || mem::size_of::<NodeHeader<K, V, K>>() != mem::size_of::<NodeHeader<K, V>>())
-            && self.is_shared_root()
-        {
-            &mut []
-        } else {
-            unsafe {
-                slice::from_raw_parts_mut(
-                    MaybeUninit::first_ptr_mut(&mut (*self.as_leaf_mut()).keys),
-                    self.len(),
-                )
-            }
+        debug_assert!(!self.is_shared_root());
+        // We cannot be the shared root, so `as_leaf_mut` is okay.
+        unsafe {
+            slice::from_raw_parts_mut(
+                MaybeUninit::first_ptr_mut(&mut (*self.as_leaf_mut()).keys),
+                self.len(),
+            )
         }
     }