@@ -297,10 +297,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
297
297
/// # }
298
298
/// ```
299
299
pub fn reserve ( & mut self , len : usize , additional : usize ) {
300
- match self . try_reserve ( len, additional) {
301
- Err ( CapacityOverflow ) => capacity_overflow ( ) ,
302
- Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
303
- Ok ( ( ) ) => { /* yay */ }
300
+ // This function is marginally shorter if it calls `try_reserve`, but
301
+ // that results in more LLVM IR being generated.
302
+ if self . needs_to_grow ( len, additional) {
303
+ match self . grow_amortized ( len, additional) {
304
+ Ok ( ( ) ) => { /* yay */ }
305
+ Err ( CapacityOverflow ) => capacity_overflow ( ) ,
306
+ Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
307
+ }
304
308
}
305
309
}
306
310
@@ -331,10 +335,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
331
335
///
332
336
/// Aborts on OOM.
333
337
pub fn reserve_exact ( & mut self , len : usize , additional : usize ) {
334
- match self . try_reserve_exact ( len, additional) {
335
- Err ( CapacityOverflow ) => capacity_overflow ( ) ,
336
- Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
337
- Ok ( ( ) ) => { /* yay */ }
338
+ // This function is marginally shorter if it calls `try_reserve_exact`,
339
+ // but that results in more LLVM IR being generated.
340
+ if self . needs_to_grow ( len, additional) {
341
+ match self . grow_exact ( len, additional) {
342
+ Ok ( ( ) ) => { /* yay */ }
343
+ Err ( CapacityOverflow ) => capacity_overflow ( ) ,
344
+ Err ( AllocError { layout, .. } ) => handle_alloc_error ( layout) ,
345
+ }
338
346
}
339
347
}
340
348
0 commit comments