Skip to content

Commit 1fff3e3

Browse files
committed
use MaybeUninit in core::slice::rotate
Code by @japaric, I just split it into individual commits
1 parent 32e5a7e commit 1fff3e3

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/libcore/slice/rotate.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use cmp;
12-
use mem;
12+
use mem::{self, MaybeUninit};
1313
use ptr;
1414

1515
/// Rotation is much faster if it has access to a little bit of memory. This
@@ -26,12 +26,6 @@ union RawArray<T> {
2626
}
2727

2828
impl<T> RawArray<T> {
29-
fn new() -> Self {
30-
unsafe { mem::uninitialized() }
31-
}
32-
fn ptr(&self) -> *mut T {
33-
unsafe { &self.typed as *const T as *mut T }
34-
}
3529
fn cap() -> usize {
3630
if mem::size_of::<T>() == 0 {
3731
usize::max_value()
@@ -88,8 +82,8 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mid: *mut T, mut right: usize) {
8882
}
8983
}
9084

91-
let rawarray = RawArray::new();
92-
let buf = rawarray.ptr();
85+
let mut rawarray = MaybeUninit::<RawArray<T>>::uninitialized();
86+
let buf = &mut (*rawarray.as_mut_ptr()).typed as *mut [T; 2] as *mut T;
9387

9488
let dim = mid.sub(left).add(right);
9589
if left <= right {

0 commit comments

Comments
 (0)