diff options
| author | bors <bors@rust-lang.org> | 2020-11-23 14:20:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-23 14:20:22 +0000 |
| commit | 40cf72108edb9b8633a9d284b238988309204494 (patch) | |
| tree | 8ea73ecde9df96d08ea95a412a3f62eb087548e2 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | |
| parent | 068320b39e3e4839d832b3aa71fa910ba170673b (diff) | |
| parent | a9915581d7cb73e7c8fb8193f48dbef36a7d09ac (diff) | |
| download | rust-40cf72108edb9b8633a9d284b238988309204494.tar.gz rust-40cf72108edb9b8633a9d284b238988309204494.zip | |
Auto merge of #79186 - JulianKnodt:str_from, r=Mark-Simulacrum
Change slice::to_vec to not use extend_from_slice I saw this [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/String.3A.3Afrom%28.26str%29.20wonky.20codegen/near/216164455), and didn't see any update from it, so I thought I'd try to fix it. This converts `to_vec` to no longer use `extend_from_slice`, but relies on knowing that the allocated capacity is the same size as the input. [Godbolt new v1](https://rust.godbolt.org/z/1bcWKG) [Godbolt new v2 w/ drop guard](https://rust.godbolt.org/z/5jn76K) [Godbolt old version](https://rust.godbolt.org/z/e4ePav) After some amount of iteration, there are now two specializations for `to_vec`, one for `Copy` types that use memcpy, and one for clone types which is the original from this PR. This is then used inside of `impl<T: Clone> FromIterator<Iter::Slice<T>> for Vec<T>` which is essentially equivalent to `&[T] -> Vec<T>`, instead of previous specialization of the `extend` function. This is because extend has to reason more about existing capacity by calling `reserve` on an existing vec, and thus produces worse asm. Downsides: This allocates the exact capacity, so I think if many items are added to this `Vec` after, it might need to allocate whereas extending may not. I also noticed the number of faults went up in the benchmarks, but not sure where from exactly.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
