@@ -390,7 +390,12 @@ impl<T, A: Allocator> Box<T, A> {
390
390
// #[unstable(feature = "new_uninit", issue = "63291")]
391
391
pub fn new_uninit_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A > {
392
392
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
393
- Box :: try_new_uninit_in ( alloc) . unwrap_or_else ( |_| handle_alloc_error ( layout) )
393
+ // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
394
+ // That would make code size bigger.
395
+ match Box :: try_new_uninit_in ( alloc) {
396
+ Ok ( m) => m,
397
+ Err ( _) => handle_alloc_error ( layout) ,
398
+ }
394
399
}
395
400
396
401
/// Constructs a new box with uninitialized contents in the provided allocator,
@@ -447,7 +452,12 @@ impl<T, A: Allocator> Box<T, A> {
447
452
// #[unstable(feature = "new_uninit", issue = "63291")]
448
453
pub fn new_zeroed_in ( alloc : A ) -> Box < mem:: MaybeUninit < T > , A > {
449
454
let layout = Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
450
- Box :: try_new_zeroed_in ( alloc) . unwrap_or_else ( |_| handle_alloc_error ( layout) )
455
+ // NOTE: Prefer match over unwrap_or_else since closure sometimes not inlineable.
456
+ // That would make code size bigger.
457
+ match Box :: try_new_zeroed_in ( alloc) {
458
+ Ok ( m) => m,
459
+ Err ( _) => handle_alloc_error ( layout) ,
460
+ }
451
461
}
452
462
453
463
/// Constructs a new `Box` with uninitialized contents, with the memory
0 commit comments