Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Inline and remove layout::size_align.
  • Loading branch information
nnethercote committed Jul 28, 2020
commit 086cecbbcc73ac2f6f42d1b6b8e3420fbc34c76e
7 changes: 1 addition & 6 deletions library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use crate::mem;
use crate::num::NonZeroUsize;
use crate::ptr::NonNull;

const fn size_align<T>() -> (usize, usize) {
(mem::size_of::<T>(), mem::align_of::<T>())
}

/// Layout of a block of memory.
///
/// An instance of `Layout` describes a particular layout of memory.
Expand Down Expand Up @@ -115,12 +111,11 @@ impl Layout {
#[rustc_const_stable(feature = "alloc_layout_const_new", since = "1.42.0")]
#[inline]
pub const fn new<T>() -> Self {
let (size, align) = size_align::<T>();
// SAFETY: the align is guaranteed by Rust to be a power of two and
// the size+align combo is guaranteed to fit in our address space. As a
// result use the unchecked constructor here to avoid inserting code
// that panics if it isn't optimized well enough.
unsafe { Layout::from_size_align_unchecked(size, align) }
unsafe { Layout::from_size_align_unchecked(mem::size_of::<T>(), mem::align_of::<T>()) }
}

/// Produces layout describing a record that could be used to
Expand Down