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