about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2021-02-06 13:33:29 +0000
committerLzu Tao <taolzu@gmail.com>2021-02-06 15:00:37 +0000
commitfb4e734f99b8efc77634dc96424cafb956e4596f (patch)
treec0461bbaf5ef3ea89fb48c546d30fca57593062a /library/alloc
parent399b6452b5d9982438be208668bc758479f13725 (diff)
downloadrust-fb4e734f99b8efc77634dc96424cafb956e4596f.tar.gz
rust-fb4e734f99b8efc77634dc96424cafb956e4596f.zip
Prefer match intead of combinators to make some Box function inlineable
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/src/boxed.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
index 949079e5b69..e87303749b4 100644
--- a/library/alloc/src/boxed.rs
+++ b/library/alloc/src/boxed.rs
@@ -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