about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-03 06:24:06 +0000
committerbors <bors@rust-lang.org>2021-10-03 06:24:06 +0000
commitc24c9067eec3aec8dd2013d24f6cd0dff3ecec4c (patch)
treeb62248940bca22a87b7914bab51600d62b5dd246 /compiler/rustc_codegen_gcc
parent77f1e504a953efbbd59673a75c3cd530d5b3c530 (diff)
parent3839ca9953e47ad91751fdfffa10c9ae8a210e3c (diff)
downloadrust-c24c9067eec3aec8dd2013d24f6cd0dff3ecec4c.tar.gz
rust-c24c9067eec3aec8dd2013d24f6cd0dff3ecec4c.zip
Auto merge of #88060 - TennyZhuang:optimize-vec-retain, r=dtolnay
Optimize unnecessary check in Vec::retain

The function `vec::Vec::retain` only have two stages:

1. Nothing was deleted.
2. Some elements were deleted.

Here is an unnecessary check `if g.deleted_cnt > 0` in the loop, and it's difficult for compiler to optimize it. I split the loop into two stages manully and keep the code clean using const generics.

I write a special but common bench case for this optimization. I call retain on vec but keep all elements.

Before and after this optimization:

```
test vec::bench_retain_whole_100000                      ... bench:      84,803 ns/iter (+/- 17,314)
```

```
test vec::bench_retain_whole_100000                      ... bench:      42,638 ns/iter (+/- 16,910)
```

The result is expected, there are two `if`s before the optimization and one `if` after.
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions