@@ -129,30 +129,30 @@ impl<'alloc> ArenaAllocator<'alloc> {
129129 let cached_idx = self . alloc_cache [ sc_idx] . get ( ) ;
130130 if cached_idx < self . typed_arenas . len ( ) {
131131 let pool = & self . typed_arenas [ cached_idx] ;
132- if pool. slot_size == slot_size {
133- if let Some ( slot_ptr) = pool. alloc_slot ( ) {
134- // SAFETY: slot_ptr was successfully allocated for this size class
135- return unsafe {
136- let dst = slot_ptr . as_ptr ( ) as * mut ArenaHeapItem < T > ;
137- dst . write ( ArenaHeapItem ( value ) ) ;
138- Ok ( ArenaPointer :: from_raw ( NonNull :: new_unchecked ( dst ) ) )
139- } ;
140- }
132+ if pool. slot_size == slot_size
133+ && let Some ( slot_ptr) = pool. alloc_slot ( )
134+ {
135+ // SAFETY: slot_ptr was successfully allocated for this size class
136+ return unsafe {
137+ let dst = slot_ptr . as_ptr ( ) as * mut ArenaHeapItem < T > ;
138+ dst . write ( ArenaHeapItem ( value ) ) ;
139+ Ok ( ArenaPointer :: from_raw ( NonNull :: new_unchecked ( dst ) ) )
140+ } ;
141141 }
142142 }
143143
144144 // try existing pools with matching slot_size first
145145 for ( i, pool) in self . typed_arenas . iter ( ) . enumerate ( ) . rev ( ) {
146- if pool. slot_size == slot_size {
147- if let Some ( slot_ptr) = pool. alloc_slot ( ) {
148- self . alloc_cache [ sc_idx ] . set ( i ) ;
149- // SAFETY: slot_ptr was successfully allocated for this size class
150- return unsafe {
151- let dst = slot_ptr . as_ptr ( ) as * mut ArenaHeapItem < T > ;
152- dst . write ( ArenaHeapItem ( value ) ) ;
153- Ok ( ArenaPointer :: from_raw ( NonNull :: new_unchecked ( dst ) ) )
154- } ;
155- }
146+ if pool. slot_size == slot_size
147+ && let Some ( slot_ptr) = pool. alloc_slot ( )
148+ {
149+ self . alloc_cache [ sc_idx ] . set ( i ) ;
150+ // SAFETY: slot_ptr was successfully allocated for this size class
151+ return unsafe {
152+ let dst = slot_ptr . as_ptr ( ) as * mut ArenaHeapItem < T > ;
153+ dst . write ( ArenaHeapItem ( value ) ) ;
154+ Ok ( ArenaPointer :: from_raw ( NonNull :: new_unchecked ( dst ) ) )
155+ } ;
156156 }
157157 }
158158
@@ -173,11 +173,11 @@ impl<'alloc> ArenaAllocator<'alloc> {
173173 }
174174 }
175175
176- // drops the value at `ptr` and returns the slot to the allocator
177- //
178- // SAFETY:
179- // `ptr` must be a live `ArenaHeapItem<T>` allocated by this allocator,
180- // must not be used after this call
176+ /// Drops the value at `ptr` and returns the slot to the allocator
177+ ///
178+ /// # Safety
179+ /// `ptr` must be a live `ArenaHeapItem<T>` allocated by this allocator,
180+ /// must not be used after this call
181181 pub unsafe fn free_slot_typed < T > ( & mut self , ptr : NonNull < ArenaHeapItem < T > > ) {
182182 // SAFETY: guaranteed by caller
183183 unsafe { core:: ptr:: drop_in_place ( ptr. as_ptr ( ) ) } ;
@@ -211,10 +211,10 @@ impl<'alloc> ArenaAllocator<'alloc> {
211211 // bump allocate raw bytes onto a BumpPage
212212 pub fn try_alloc_bytes ( & mut self , layout : Layout ) -> Result < NonNull < [ u8 ] > , ArenaAllocError > {
213213 // try the most recent raw page first
214- if let Some ( page) = self . raw_arenas . last ( ) {
215- if let Ok ( ptr) = page. try_alloc ( layout) {
216- return Ok ( ptr ) ;
217- }
214+ if let Some ( page) = self . raw_arenas . last ( )
215+ && let Ok ( ptr) = page. try_alloc ( layout)
216+ {
217+ return Ok ( ptr ) ;
218218 }
219219 // allocate a new raw page with margin for padding
220220 let margin = 64 ;
0 commit comments