diff options
| author | bors <bors@rust-lang.org> | 2018-07-29 21:37:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-29 21:37:47 +0000 |
| commit | 866a713258915e6cbb212d135f751a6a8c9e1c0a (patch) | |
| tree | a167fe06a630b04423cfd159186a0eacc27afc52 /src/librustc_codegen_llvm/back | |
| parent | 70cac59031d5c33962a1f53cdca9359c0dcd1f9f (diff) | |
| parent | 59c8a279daf6912b99ba089ff6dafbfc3469831e (diff) | |
| download | rust-866a713258915e6cbb212d135f751a6a8c9e1c0a.tar.gz rust-866a713258915e6cbb212d135f751a6a8c9e1c0a.zip | |
Auto merge of #52738 - ljedrz:push_to_extend, r=eddyb
Replace push loops with extend() where possible Or set the vector capacity where I couldn't do it. According to my [simple benchmark](https://gist.github.com/ljedrz/568e97621b749849684c1da71c27dceb) `extend`ing a vector can be over **10 times** faster than `push`ing to it in a loop: 10 elements (6.1 times faster): ``` test bench_extension ... bench: 75 ns/iter (+/- 23) test bench_push_loop ... bench: 458 ns/iter (+/- 142) ``` 100 elements (11.12 times faster): ``` test bench_extension ... bench: 87 ns/iter (+/- 26) test bench_push_loop ... bench: 968 ns/iter (+/- 3,528) ``` 1000 elements (11.04 times faster): ``` test bench_extension ... bench: 311 ns/iter (+/- 9) test bench_push_loop ... bench: 3,436 ns/iter (+/- 233) ``` Seems like a good idea to use `extend` as much as possible.
Diffstat (limited to 'src/librustc_codegen_llvm/back')
| -rw-r--r-- | src/librustc_codegen_llvm/back/rpath.rs | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/src/librustc_codegen_llvm/back/rpath.rs b/src/librustc_codegen_llvm/back/rpath.rs index e73073cfad0..2c3a143646c 100644 --- a/src/librustc_codegen_llvm/back/rpath.rs +++ b/src/librustc_codegen_llvm/back/rpath.rs @@ -152,9 +152,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> { (Some(_), Some(b)) if b == Component::ParentDir => return None, (Some(a), Some(_)) => { comps.push(Component::ParentDir); - for _ in itb { - comps.push(Component::ParentDir); - } + comps.extend(itb.map(|_| Component::ParentDir)); comps.push(a); comps.extend(ita.by_ref()); break; |
