| 1 |
// Copyright (c) 2019-2022, The rav1e contributors. All rights reserved |
| 2 |
// |
| 3 |
// This source code is subject to the terms of the BSD 2 Clause License and |
| 4 |
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 5 |
// was not distributed with this source code in the LICENSE file, you can |
| 6 |
// obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 7 |
// Media Patent License 1.0 was not distributed with this source code in the |
| 8 |
// PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 9 |
|
| 10 |
use std::mem::MaybeUninit; |
| 11 |
|
| 12 |
pub fn init_slice_repeat_mut<T: Copy>( |
| 13 |
slice: &'_ mut [MaybeUninit<T>], value: T, |
| 14 |
) -> &'_ mut [T] { |
| 15 |
// Fill all of slice |
| 16 |
for a in slice.iter_mut() { |
| 17 |
*a = MaybeUninit::new(value); |
| 18 |
} |
| 19 |
|
| 20 |
// SAFETY: Defined behavior, since all elements of slice are initialized |
| 21 |
unsafe { slice_assume_init_mut(slice) } |
| 22 |
} |
| 23 |
|
| 24 |
/// Assume all the elements are initialized. |
| 25 |
#[inline(always)] |
| 26 |
pub unsafe fn slice_assume_init_mut<T: Copy>( |
| 27 |
slice: &'_ mut [MaybeUninit<T>], |
| 28 |
) -> &'_ mut [T] { |
| 29 |
&mut *(slice as *mut [MaybeUninit<T>] as *mut [T]) |
| 30 |
} |