about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2014-12-05 11:29:15 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2014-12-05 11:29:41 -0800
commite20ea0b67dbd5428bc3d355862692f1efecd378c (patch)
treeb26b43edaf997bb45de57677c64806991fafb8a8 /src
parent4573da6f4ffb276c31773679fd19581fc15ded8f (diff)
downloadrust-e20ea0b67dbd5428bc3d355862692f1efecd378c.tar.gz
rust-e20ea0b67dbd5428bc3d355862692f1efecd378c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/libcollections/vec.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index 2396cf8cec6..34d9397742d 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -688,11 +688,12 @@ impl<T> Vec<T> {
                 Some(new_cap) => {
                     let amort_cap = new_cap.next_power_of_two();
                     // next_power_of_two will overflow to exactly 0 for really big capacities
-                    if amort_cap == 0 {
-                        self.grow_capacity(new_cap);
+                    let cap = if amort_cap == 0 {
+                        new_cap
                     } else {
-                        self.grow_capacity(amort_cap);
-                    }
+                        amort_cap
+                    };
+                    self.grow_capacity(cap)
                 }
             }
         }