]> git.lizzy.rs Git - rust.git/commit - src/librustc_llvm/build.rs
Rollup merge of #74677 - ssomers:btree_cleanup_2, r=Amanieu
authorYuki Okushi <huyuumi.dev@gmail.com>
Fri, 24 Jul 2020 09:56:38 +0000 (18:56 +0900)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2020 09:56:38 +0000 (18:56 +0900)
commitfab9b1d4cd5a788f46d94077b49da285ce782b74
treedd0eeeddbd39e82beb10ccd52d81f69c75e1ab8b
parent7f2bb29907c333ebb71e0cf651302ebc4fc0cb1e
parentfacc46fd0a85408bc05aa19b80131e3cfb5fe3dd
Rollup merge of #74677 - ssomers:btree_cleanup_2, r=Amanieu

Remove needless unsafety from BTreeMap::drain_filter

Remove one piece of unsafe code in the iteration over the iterator returned by BTreeMap::drain_filter.
- Changes an explicitly unspecified part of the API: when the user-supplied predicate (or some of BTreeMap's code) panicked, and the caller tries to use the iterator again, we no longer offer the same key/value pair to the predicate again but pretend the iterator has finished. Note that Miri does not find UB in the test case added here with the unsafe code (or without).
- Makes the code a little easier on the eyes.
- Makes the code a little harder on the CPU:
```
benchcmp c0 c2 --threshold 3
 name                                         c0 ns/iter  c2 ns/iter  diff ns/iter  diff %  speedup
 btree::set::clone_100_and_drain_all          2,794       2,900                106   3.79%   x 0.96
 btree::set::clone_100_and_drain_half         2,604       2,964                360  13.82%   x 0.88
 btree::set::clone_10k_and_drain_half         287,770     322,755           34,985  12.16%   x 0.89
```
r? @Amanieu
src/liballoc/collections/btree/map.rs
src/liballoc/tests/btree/map.rs