Skip to content

Commit e0ba4b7

Browse files
committed
Avoid instantiating try_reserve{,_exact}.
This reduces the amount of LLVM IR generated, slightly improving compile times.
1 parent 6057361 commit e0ba4b7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/liballoc/raw_vec.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
291291
/// # }
292292
/// ```
293293
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+
}
298302
}
299303
}
300304

@@ -327,10 +331,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
327331
///
328332
/// Aborts on OOM.
329333
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+
}
334342
}
335343
}
336344

0 commit comments

Comments
 (0)