mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Mark slice::reverse
unstably const
This commit is contained in:
parent
49761b073c
commit
03c2ac248f
@ -987,8 +987,9 @@ impl<T> [T] {
|
|||||||
/// assert!(v == [3, 2, 1]);
|
/// assert!(v == [3, 2, 1]);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_const_unstable(feature = "const_slice_reverse", issue = "135120")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn reverse(&mut self) {
|
pub const fn reverse(&mut self) {
|
||||||
let half_len = self.len() / 2;
|
let half_len = self.len() / 2;
|
||||||
let Range { start, end } = self.as_mut_ptr_range();
|
let Range { start, end } = self.as_mut_ptr_range();
|
||||||
|
|
||||||
@ -1011,7 +1012,7 @@ impl<T> [T] {
|
|||||||
revswap(front_half, back_half, half_len);
|
revswap(front_half, back_half, half_len);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
|
const fn revswap<T>(a: &mut [T], b: &mut [T], n: usize) {
|
||||||
debug_assert!(a.len() == n);
|
debug_assert!(a.len() == n);
|
||||||
debug_assert!(b.len() == n);
|
debug_assert!(b.len() == n);
|
||||||
|
|
||||||
@ -1019,7 +1020,8 @@ impl<T> [T] {
|
|||||||
// this check tells LLVM that the indexing below is
|
// this check tells LLVM that the indexing below is
|
||||||
// in-bounds. Then after inlining -- once the actual
|
// in-bounds. Then after inlining -- once the actual
|
||||||
// lengths of the slices are known -- it's removed.
|
// lengths of the slices are known -- it's removed.
|
||||||
let (a, b) = (&mut a[..n], &mut b[..n]);
|
let (a, _) = a.split_at_mut(n);
|
||||||
|
let (b, _) = b.split_at_mut(n);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < n {
|
while i < n {
|
||||||
|
Loading…
Reference in New Issue
Block a user