about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-08 18:42:21 +0000
committerbors <bors@rust-lang.org>2014-12-08 18:42:21 +0000
commit84a7615418749d663d54dd9223a15098b834e2a0 (patch)
tree9c8fd2f5ca13dc3e56db196ecd26894b9961003d
parent2e996ffb46d4f9e58d111d7e0de21602ac92411f (diff)
parente20ea0b67dbd5428bc3d355862692f1efecd378c (diff)
downloadrust-84a7615418749d663d54dd9223a15098b834e2a0.tar.gz
rust-84a7615418749d663d54dd9223a15098b834e2a0.zip
auto merge of #19574 : erickt/rust/vec-reserve, r=alexcrichton
(I don't understand why this works, and so I don't quite trust this yet. I'm pushing it up to see if anyone else can replicate this performance increase)

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 reduce my Rust compile time from 41 minutes to 27 minutes.

Closes #19281.
-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 c73c9b0c9ed..1509306bbf5 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -682,11 +682,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)
                 }
             }
         }