rust/library/alloc/src
Mara Bos 40889819ee
Rollup merge of #78857 - SkiFire13:bheap-opt, r=KodrAus
Improve BinaryHeap performance

By changing the condition in the loops from `child < end` to `child < end - 1` we're guaranteed that `right = child + 1 < end` and since finding the index of the biggest sibling can be done with an arithmetic operation we can remove a branch from the loop body. The case where there's no right child, i.e. `child == end - 1` is instead handled outside the loop, after it ends; note that if the loops ends early we can use `return` instead of `break` since the check `child == end - 1` will surely fail.

I've also removed a call to `<[T]>::swap` that was hiding a bound check that [wasn't being optimized by LLVM](https://godbolt.org/z/zrhdGM).

A quick benchmarks on my pc shows that the gains are pretty significant:

|name                 |before ns/iter  |after ns/iter  |diff ns/iter  |diff %    |speedup |
|---------------------|----------------|---------------|--------------|----------|--------|
|find_smallest_1000   | 352,565        | 260,098       |     -92,467  | -26.23%  | x 1.36 |
|from_vec             | 676,795        | 473,934       |    -202,861  | -29.97%  | x 1.43 |
|into_sorted_vec      | 469,511        | 304,275       |    -165,236  | -35.19%  | x 1.54 |
|pop                  | 483,198        | 373,778       |    -109,420  | -22.64%  | x 1.29 |

The other 2 benchmarks for `BinaryHeap` (`peek_mut_deref_mut` and `push`) weren't impacted and as such didn't show any significant change.
2020-11-12 19:46:11 +01:00
..
alloc Replace Memoryblock with NonNull<[u8]> 2020-08-04 18:03:34 +02:00
collections Rollup merge of #78857 - SkiFire13:bheap-opt, r=KodrAus 2020-11-12 19:46:11 +01:00
prelude mv std libs to library/ 2020-07-27 19:51:13 -05:00
raw_vec Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
rc Add tests for weak into/from raw 2020-09-12 10:38:33 -05:00
sync Add tests for weak into/from raw 2020-09-12 10:38:33 -05:00
alloc.rs Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00
borrow.rs Update library functions with stability attributes 2020-09-22 10:05:58 -07:00
boxed.rs fix Box::into_unique 2020-10-27 17:02:42 +01:00
fmt.rs Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
lib.rs BTreeMap: fix pointer provenance rules, make borrowing explicit 2020-11-09 09:13:50 +01:00
macros.rs Fix doc links to std::fmt 2020-10-31 18:02:55 +07:00
raw_vec.rs Merge remote-tracking branch 'upstream/master' into box-alloc 2020-10-25 16:32:28 +01:00
rc.rs Don't say you "should" use fully qualified syntax 2020-10-28 16:49:30 -07:00
slice.rs Rollup merge of #77969 - ryan-scott-dev:bigo-notation-consistency, r=m-ou-se 2020-10-23 18:26:26 +09:00
str.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
string.rs Prevent String::retain from creating non-utf8 strings when abusing panic 2020-10-29 11:58:12 +01:00
sync.rs Don't say you "should" use fully qualified syntax 2020-10-28 16:49:30 -07:00
task.rs Allow unstable From impl for [Raw]Waker. 2020-09-11 13:36:45 +02:00
tests.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
vec.rs remove needs_drop 2020-11-07 21:40:55 +01:00