1
Fork 0

Rename private helper method allocate_for_unsized to allocate_for_layout

This commit is contained in:
Simon Sapin 2019-08-17 15:39:21 +02:00
parent ba0328327c
commit b79ce1b1b1
2 changed files with 10 additions and 10 deletions

View file

@ -351,7 +351,7 @@ impl<T> Rc<T> {
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> { pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> {
unsafe { unsafe {
Rc::from_ptr(Rc::allocate_for_unsized( Rc::from_ptr(Rc::allocate_for_layout(
Layout::new::<T>(), Layout::new::<T>(),
|mem| mem as *mut RcBox<mem::MaybeUninit<T>>, |mem| mem as *mut RcBox<mem::MaybeUninit<T>>,
)) ))
@ -880,11 +880,11 @@ impl Rc<dyn Any> {
impl<T: ?Sized> Rc<T> { impl<T: ?Sized> Rc<T> {
/// Allocates an `RcBox<T>` with sufficient space for /// Allocates an `RcBox<T>` with sufficient space for
/// an unsized value where the value has the layout provided. /// a possibly-unsized value where the value has the layout provided.
/// ///
/// The function `mem_to_rcbox` is called with the data pointer /// The function `mem_to_rcbox` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`. /// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
unsafe fn allocate_for_unsized( unsafe fn allocate_for_layout(
value_layout: Layout, value_layout: Layout,
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcBox<T> mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcBox<T>
) -> *mut RcBox<T> { ) -> *mut RcBox<T> {
@ -913,7 +913,7 @@ impl<T: ?Sized> Rc<T> {
/// Allocates an `RcBox<T>` with sufficient space for an unsized value /// Allocates an `RcBox<T>` with sufficient space for an unsized value
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut RcBox<T> { unsafe fn allocate_for_ptr(ptr: *const T) -> *mut RcBox<T> {
// Allocate for the `RcBox<T>` using the given value. // Allocate for the `RcBox<T>` using the given value.
Self::allocate_for_unsized( Self::allocate_for_layout(
Layout::for_value(&*ptr), Layout::for_value(&*ptr),
|mem| set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>, |mem| set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>,
) )
@ -944,7 +944,7 @@ impl<T: ?Sized> Rc<T> {
impl<T> Rc<[T]> { impl<T> Rc<[T]> {
/// Allocates an `RcBox<[T]>` with the given length. /// Allocates an `RcBox<[T]>` with the given length.
unsafe fn allocate_for_slice(len: usize) -> *mut RcBox<[T]> { unsafe fn allocate_for_slice(len: usize) -> *mut RcBox<[T]> {
Self::allocate_for_unsized( Self::allocate_for_layout(
Layout::array::<T>(len).unwrap(), Layout::array::<T>(len).unwrap(),
|mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut RcBox<[T]>, |mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut RcBox<[T]>,
) )

View file

@ -335,7 +335,7 @@ impl<T> Arc<T> {
#[unstable(feature = "new_uninit", issue = "63291")] #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit() -> Arc<mem::MaybeUninit<T>> { pub fn new_uninit() -> Arc<mem::MaybeUninit<T>> {
unsafe { unsafe {
Arc::from_ptr(Arc::allocate_for_unsized( Arc::from_ptr(Arc::allocate_for_layout(
Layout::new::<T>(), Layout::new::<T>(),
|mem| mem as *mut ArcInner<mem::MaybeUninit<T>>, |mem| mem as *mut ArcInner<mem::MaybeUninit<T>>,
)) ))
@ -736,11 +736,11 @@ impl<T: ?Sized> Arc<T> {
impl<T: ?Sized> Arc<T> { impl<T: ?Sized> Arc<T> {
/// Allocates an `ArcInner<T>` with sufficient space for /// Allocates an `ArcInner<T>` with sufficient space for
/// an unsized value where the value has the layout provided. /// a possibly-unsized value where the value has the layout provided.
/// ///
/// The function `mem_to_arcinner` is called with the data pointer /// The function `mem_to_arcinner` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `ArcInner<T>`. /// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
unsafe fn allocate_for_unsized( unsafe fn allocate_for_layout(
value_layout: Layout, value_layout: Layout,
mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T> mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>
) -> *mut ArcInner<T> { ) -> *mut ArcInner<T> {
@ -768,7 +768,7 @@ impl<T: ?Sized> Arc<T> {
/// Allocates an `ArcInner<T>` with sufficient space for an unsized value. /// Allocates an `ArcInner<T>` with sufficient space for an unsized value.
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut ArcInner<T> { unsafe fn allocate_for_ptr(ptr: *const T) -> *mut ArcInner<T> {
// Allocate for the `ArcInner<T>` using the given value. // Allocate for the `ArcInner<T>` using the given value.
Self::allocate_for_unsized( Self::allocate_for_layout(
Layout::for_value(&*ptr), Layout::for_value(&*ptr),
|mem| set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>, |mem| set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>,
) )
@ -799,7 +799,7 @@ impl<T: ?Sized> Arc<T> {
impl<T> Arc<[T]> { impl<T> Arc<[T]> {
/// Allocates an `ArcInner<[T]>` with the given length. /// Allocates an `ArcInner<[T]>` with the given length.
unsafe fn allocate_for_slice(len: usize) -> *mut ArcInner<[T]> { unsafe fn allocate_for_slice(len: usize) -> *mut ArcInner<[T]> {
Self::allocate_for_unsized( Self::allocate_for_layout(
Layout::array::<T>(len).unwrap(), Layout::array::<T>(len).unwrap(),
|mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut ArcInner<[T]>, |mem| ptr::slice_from_raw_parts_mut(mem as *mut T, len) as *mut ArcInner<[T]>,
) )