From fb4e734f99b8efc77634dc96424cafb956e4596f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 6 Feb 2021 13:33:29 +0000 Subject: [PATCH] Prefer match intead of combinators to make some Box function inlineable --- library/alloc/src/boxed.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 949079e5b699c..e87303749b423 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -390,7 +390,12 @@ impl Box { // #[unstable(feature = "new_uninit", issue = "63291")] pub fn new_uninit_in(alloc: A) -> Box, A> { let layout = Layout::new::>(); - 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 Box { // #[unstable(feature = "new_uninit", issue = "63291")] pub fn new_zeroed_in(alloc: A) -> Box, A> { let layout = Layout::new::>(); - 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