@@ -216,34 +216,29 @@ impl<T> TypedArena<T> {
216
216
#[ cold]
217
217
fn grow ( & self , n : usize ) {
218
218
unsafe {
219
- // We need the element size in to convert chunk sizes (ranging from
219
+ // We need the element size to convert chunk sizes (ranging from
220
220
// PAGE to HUGE_PAGE bytes) to element counts.
221
221
let elem_size = cmp:: max ( 1 , mem:: size_of :: < T > ( ) ) ;
222
222
let mut chunks = self . chunks . borrow_mut ( ) ;
223
- let ( chunk , mut new_capacity) ;
223
+ let mut new_capacity;
224
224
if let Some ( last_chunk) = chunks. last_mut ( ) {
225
225
let used_bytes = self . ptr . get ( ) as usize - last_chunk. start ( ) as usize ;
226
- let currently_used_cap = used_bytes / mem:: size_of :: < T > ( ) ;
227
- last_chunk. entries = currently_used_cap;
228
- if last_chunk. storage . reserve_in_place ( currently_used_cap, n) {
229
- self . end . set ( last_chunk. end ( ) ) ;
230
- return ;
231
- } else {
232
- // If the previous chunk's capacity is less than HUGE_PAGE
233
- // bytes, then this chunk will be least double the previous
234
- // chunk's size.
235
- new_capacity = last_chunk. storage . capacity ( ) ;
236
- if new_capacity < HUGE_PAGE / elem_size {
237
- new_capacity = new_capacity. checked_mul ( 2 ) . unwrap ( ) ;
238
- }
226
+ last_chunk. entries = used_bytes / mem:: size_of :: < T > ( ) ;
227
+
228
+ // If the previous chunk's capacity is less than HUGE_PAGE
229
+ // bytes, then this chunk will be least double the previous
230
+ // chunk's size.
231
+ new_capacity = last_chunk. storage . capacity ( ) ;
232
+ if new_capacity < HUGE_PAGE / elem_size {
233
+ new_capacity = new_capacity. checked_mul ( 2 ) . unwrap ( ) ;
239
234
}
240
235
} else {
241
236
new_capacity = PAGE / elem_size;
242
237
}
243
238
// Also ensure that this chunk can fit `n`.
244
239
new_capacity = cmp:: max ( n, new_capacity) ;
245
240
246
- chunk = TypedArenaChunk :: < T > :: new ( new_capacity) ;
241
+ let chunk = TypedArenaChunk :: < T > :: new ( new_capacity) ;
247
242
self . ptr . set ( chunk. start ( ) ) ;
248
243
self . end . set ( chunk. end ( ) ) ;
249
244
chunks. push ( chunk) ;
@@ -350,28 +345,25 @@ impl DroplessArena {
350
345
fn grow ( & self , needed_bytes : usize ) {
351
346
unsafe {
352
347
let mut chunks = self . chunks . borrow_mut ( ) ;
353
- let ( chunk , mut new_capacity) ;
348
+ let mut new_capacity;
354
349
if let Some ( last_chunk) = chunks. last_mut ( ) {
355
- let used_bytes = self . ptr . get ( ) as usize - last_chunk. start ( ) as usize ;
356
- if last_chunk. storage . reserve_in_place ( used_bytes, needed_bytes) {
357
- self . end . set ( last_chunk. end ( ) ) ;
358
- return ;
359
- } else {
360
- // If the previous chunk's capacity is less than HUGE_PAGE
361
- // bytes, then this chunk will be least double the previous
362
- // chunk's size.
363
- new_capacity = last_chunk. storage . capacity ( ) ;
364
- if new_capacity < HUGE_PAGE {
365
- new_capacity = new_capacity. checked_mul ( 2 ) . unwrap ( ) ;
366
- }
350
+ // There is no need to update `last_chunk.entries` because that
351
+ // field isn't used by `DroplessArena`.
352
+
353
+ // If the previous chunk's capacity is less than HUGE_PAGE
354
+ // bytes, then this chunk will be least double the previous
355
+ // chunk's size.
356
+ new_capacity = last_chunk. storage . capacity ( ) ;
357
+ if new_capacity < HUGE_PAGE {
358
+ new_capacity = new_capacity. checked_mul ( 2 ) . unwrap ( ) ;
367
359
}
368
360
} else {
369
361
new_capacity = PAGE ;
370
362
}
371
363
// Also ensure that this chunk can fit `needed_bytes`.
372
364
new_capacity = cmp:: max ( needed_bytes, new_capacity) ;
373
365
374
- chunk = TypedArenaChunk :: < u8 > :: new ( new_capacity) ;
366
+ let chunk = TypedArenaChunk :: < u8 > :: new ( new_capacity) ;
375
367
self . ptr . set ( chunk. start ( ) ) ;
376
368
self . end . set ( chunk. end ( ) ) ;
377
369
chunks. push ( chunk) ;
0 commit comments