1
Fork 0

Rollup merge of #81826 - tesuji:inline-box-zeros, r=Amanieu

Prefer match over combinators to make some Box methods inlineable

Hopefully this patch would make two snippets generated identical code: <https://rust.godbolt.org/z/fjrj4E>.
This commit is contained in:
Dylan DPC 2021-02-09 02:39:53 +01:00 committed by GitHub
commit d19f37541c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -390,7 +390,12 @@ impl<T, A: Allocator> Box<T, A> {
// #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
let layout = Layout::new::<mem::MaybeUninit<T>>();
Box::try_new_uninit_in(alloc).unwrap_or_else(|_| handle_alloc_error(layout))
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
// That would make code size bigger.
match Box::try_new_uninit_in(alloc) {
Ok(m) => m,
Err(_) => handle_alloc_error(layout),
}
}
/// Constructs a new box with uninitialized contents in the provided allocator,
@ -447,7 +452,12 @@ impl<T, A: Allocator> Box<T, A> {
// #[unstable(feature = "new_uninit", issue = "63291")]
pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> {
let layout = Layout::new::<mem::MaybeUninit<T>>();
Box::try_new_zeroed_in(alloc).unwrap_or_else(|_| handle_alloc_error(layout))
// NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
// That would make code size bigger.
match Box::try_new_zeroed_in(alloc) {
Ok(m) => m,
Err(_) => handle_alloc_error(layout),
}
}
/// Constructs a new `Box` with uninitialized contents, with the memory