diff options
| author | bors <bors@rust-lang.org> | 2019-12-15 07:17:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-15 07:17:06 +0000 |
| commit | a605441e049f0b6d5f7715b94b8ac4662fd7fcf6 (patch) | |
| tree | f60596ca9dbae104e70cfd1a31aef5a90a255293 /src/liballoc | |
| parent | fc6b5d6efe163060bde31cc1c801086ed7ebc8f1 (diff) | |
| parent | e5c34411f979712fc21f338c730158a2ac399c75 (diff) | |
Auto merge of #67310 - Centril:rollup-22jiyow, r=Centril
Rollup of 6 pull requests Successful merges: - #67255 (Remove i686-unknown-dragonfly target) - #67267 (Fix signature of `__wasilibc_find_relpath`) - #67282 (Fix example code of OpenOptions::open) - #67289 (Do not ICE on unnamed future) - #67300 (Restore original implementation of Vec::retain) - #67305 (Doc typo) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/vec.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 52b45b0b8fe..2ad4e22884e 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1079,7 +1079,22 @@ impl<T> Vec<T> { pub fn retain<F>(&mut self, mut f: F) where F: FnMut(&T) -> bool { - self.drain_filter(|x| !f(x)); + let len = self.len(); + let mut del = 0; + { + let v = &mut **self; + + for i in 0..len { + if !f(&v[i]) { + del += 1; + } else if del > 0 { + v.swap(i - del, i); + } + } + } + if del > 0 { + self.truncate(len - del); + } } /// Removes all but the first of consecutive elements in the vector that resolve to the same |
