diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-08-03 01:05:12 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-03 01:05:12 +0900 |
| commit | 8c331ee4709c73b23f0f4c7525661ea7d47c8467 (patch) | |
| tree | d4bf4379d3ac60528149c94046fc677c06d08b96 /library/alloc | |
| parent | e8876ae2c11f341565059b900eeae1254a9accf1 (diff) | |
| parent | c4f4639e1a2eb07d17e7393a1c7f0594f0c11faf (diff) | |
| download | rust-8c331ee4709c73b23f0f4c7525661ea7d47c8467.tar.gz rust-8c331ee4709c73b23f0f4c7525661ea7d47c8467.zip | |
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
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/collections/btree/node.rs | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index f7bd64608d6..9352c5806a4 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -466,12 +466,6 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> { fn into_val_slice(self) -> &'a [V] { unsafe { slice::from_raw_parts(MaybeUninit::first_ptr(&self.as_leaf().vals), self.len()) } } - - fn into_slices(self) -> (&'a [K], &'a [V]) { - // SAFETY: equivalent to reborrow() except not requiring Type: 'a - let k = unsafe { ptr::read(&self) }; - (k.into_key_slice(), self.into_val_slice()) - } } 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 impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Immut<'a>, K, V, NodeType>, marker::KV> { pub fn into_kv(self) -> (&'a K, &'a V) { - unsafe { - let (keys, vals) = self.node.into_slices(); - (keys.get_unchecked(self.idx), vals.get_unchecked(self.idx)) - } + let keys = self.node.into_key_slice(); + let vals = self.node.into_val_slice(); + unsafe { (keys.get_unchecked(self.idx), vals.get_unchecked(self.idx)) } } } |
