@@ -453,43 +453,36 @@ impl DroplessArena {
453453 }
454454 }
455455
456- /// Allocates a byte slice with specified layout from the current memory
457- /// chunk. Returns `None` if there is no free space left to satisfy the
458- /// request.
459- #[ inline]
460- fn alloc_raw_without_grow ( & self , layout : Layout ) -> Option < * mut u8 > {
461- let start = self . start . get ( ) . addr ( ) ;
462- let old_end = self . end . get ( ) ;
463- let end = old_end. addr ( ) ;
464-
465- // Align allocated bytes so that `self.end` stays aligned to DROPLESS_ALIGNMENT
466- let bytes = align_up ( layout. size ( ) , DROPLESS_ALIGNMENT ) ;
467-
468- // Tell LLVM that `end` is aligned to DROPLESS_ALIGNMENT
469- unsafe { intrinsics:: assume ( end == align_down ( end, DROPLESS_ALIGNMENT ) ) } ;
470-
471- let new_end = align_down ( end. checked_sub ( bytes) ?, layout. align ( ) ) ;
472- if start <= new_end {
473- let new_end = old_end. with_addr ( new_end) ;
474- // `new_end` is aligned to DROPLESS_ALIGNMENT as `align_down` preserves alignment
475- // as both `end` and `bytes` are already aligned to DROPLESS_ALIGNMENT.
476- self . end . set ( new_end) ;
477- Some ( new_end)
478- } else {
479- None
480- }
481- }
482-
483456 #[ inline]
484457 pub fn alloc_raw ( & self , layout : Layout ) -> * mut u8 {
485458 assert ! ( layout. size( ) != 0 ) ;
486459
487460 // This loop executes once or twice: if allocation fails the first
488461 // time, the `grow` ensures it will succeed the second time.
489462 loop {
490- if let Some ( a) = self . alloc_raw_without_grow ( layout) {
491- return a;
463+ let start = self . start . get ( ) . addr ( ) ;
464+ let old_end = self . end . get ( ) ;
465+ let end = old_end. addr ( ) ;
466+
467+ // Align allocated bytes so that `self.end` stays aligned to
468+ // DROPLESS_ALIGNMENT.
469+ let bytes = align_up ( layout. size ( ) , DROPLESS_ALIGNMENT ) ;
470+
471+ // Tell LLVM that `end` is aligned to DROPLESS_ALIGNMENT.
472+ unsafe { intrinsics:: assume ( end == align_down ( end, DROPLESS_ALIGNMENT ) ) } ;
473+
474+ if let Some ( sub) = end. checked_sub ( bytes) {
475+ let new_end = align_down ( sub, layout. align ( ) ) ;
476+ if start <= new_end {
477+ let new_end = old_end. with_addr ( new_end) ;
478+ // `new_end` is aligned to DROPLESS_ALIGNMENT as `align_down`
479+ // preserves alignment as both `end` and `bytes` are already
480+ // aligned to DROPLESS_ALIGNMENT.
481+ self . end . set ( new_end) ;
482+ return new_end;
483+ }
492484 }
485+
493486 // No free space left. Allocate a new chunk to satisfy the request.
494487 // On failure the grow will panic or abort.
495488 self . grow ( layout) ;
0 commit comments