collections: dramatically speed up Vec::reserve with magic

Somehow llvm is able to optimize this version of Vec::reserve
into dramatically faster than the old version. In micro-benchmarks
this was 2-10 times faster. It also shaved 14 minutes off of
rust's compile times.

Closes #19281.
This commit is contained in:
Erick Tryzelaar 2014-12-05 11:29:15 -08:00
parent 4573da6f4f
commit e20ea0b67d

View File

@ -688,11 +688,12 @@ impl<T> Vec<T> {
Some(new_cap) => { Some(new_cap) => {
let amort_cap = new_cap.next_power_of_two(); let amort_cap = new_cap.next_power_of_two();
// next_power_of_two will overflow to exactly 0 for really big capacities // next_power_of_two will overflow to exactly 0 for really big capacities
if amort_cap == 0 { let cap = if amort_cap == 0 {
self.grow_capacity(new_cap); new_cap
} else { } else {
self.grow_capacity(amort_cap); amort_cap
} };
self.grow_capacity(cap)
} }
} }
} }