@@ -151,32 +151,32 @@ impl<T> TypedArena<T> {
151
151
152
152
let ptr = self . ptr . get ( ) ;
153
153
154
- let ptr = if ptr == self . end . get ( ) {
155
- self . grow_and_alloc ( )
156
- } else {
157
- // Advance the pointer.
158
- unsafe {
159
- self . ptr . set ( ptr. offset ( 1 ) ) ;
160
- }
161
- ptr
162
- } ;
163
-
164
154
unsafe {
165
- // Write into uninitialized memory.
166
- ptr:: write ( ptr, object) ;
167
- & mut * ptr
155
+ if std:: intrinsics:: unlikely ( ptr == self . end . get ( ) ) {
156
+ self . grow_and_alloc ( object)
157
+ } else {
158
+ self . alloc_unchecked ( ptr, object)
159
+ }
168
160
}
169
161
}
170
162
163
+ #[ inline( always) ]
164
+ unsafe fn alloc_unchecked ( & self , ptr : * mut T , object : T ) -> & mut T {
165
+ // Advance the pointer.
166
+ self . ptr . set ( ptr. offset ( 1 ) ) ;
167
+ // Write into uninitialized memory.
168
+ ptr:: write ( ptr, object) ;
169
+ & mut * ptr
170
+ }
171
+
171
172
#[ inline( never) ]
172
173
#[ cold]
173
- fn grow_and_alloc ( & self ) -> * mut T {
174
+ fn grow_and_alloc ( & self , object : T ) -> & mut T {
175
+ // We move the object in this function so if it has a destructor
176
+ // the fast path need not have an unwind handler to destroy it
174
177
self . grow ( 1 ) ;
175
178
unsafe {
176
- let ptr = self . ptr . get ( ) ;
177
- // Advance the pointer.
178
- self . ptr . set ( ptr. offset ( 1 ) ) ;
179
- ptr
179
+ self . alloc_unchecked ( self . ptr . get ( ) , object)
180
180
}
181
181
}
182
182
@@ -355,6 +355,11 @@ pub fn atest2(a: &SyncDroplessArena, b: Box<usize>) -> &Box<usize> {
355
355
a. promote ( b)
356
356
}
357
357
358
+ #[ no_mangle]
359
+ pub fn atest6 ( a : & SyncDroplessArena , b : usize ) -> & usize {
360
+ a. promote ( b)
361
+ }
362
+
358
363
#[ no_mangle]
359
364
pub fn atest3 ( a : & DroplessArena ) {
360
365
a. align ( 8 ) ;
@@ -479,7 +484,7 @@ impl DroplessArena {
479
484
// Find some way to guarantee this doesn't happen for small fixed size types
480
485
let ptr = self . ptr . get ( ) ;
481
486
let future_end = intrinsics:: arith_offset ( ptr, bytes as isize ) ;
482
- if /* std::intrinsics::unlikely(*/ ( future_end as * mut u8 ) >= self . end . get ( ) /*)*/ {
487
+ if std:: intrinsics:: unlikely ( ( future_end as * mut u8 ) >= self . end . get ( ) ) {
483
488
self . grow_and_alloc_raw ( bytes)
484
489
} else {
485
490
self . alloc_raw_unchecked ( ptr, bytes)
0 commit comments