Skip to content

Commit

Permalink
Merge pull request #888 from NobodyXu/fix/retain-mut
Browse files Browse the repository at this point in the history
Fix MSRV: Remove use of `Vec::retain_mut`
  • Loading branch information
NobodyXu authored Oct 21, 2023
2 parents 4f9866e + fd2330c commit 8cf12c5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ impl Build {
}

// Try waiting on them.
pendings.retain_mut(|(cmd, program, child, token)| {
retain_unordered_mut(&mut pendings, |(cmd, program, child, token)| {
match try_wait_on_child(cmd, program, &mut child.0, &mut stdout) {
Ok(Some(())) => {
// Task done, remove the entry
Expand Down Expand Up @@ -4127,3 +4127,21 @@ impl Drop for PrintThread {
self.handle.take().unwrap().join().unwrap();
}
}

/// Remove all element in `vec` which `f(element)` returns `false`.
///
/// TODO: Remove this once the MSRV is bumped to v1.61
#[cfg(feature = "parallel")]
fn retain_unordered_mut<T, F>(vec: &mut Vec<T>, mut f: F)
where
F: FnMut(&mut T) -> bool,
{
let mut i = 0;
while i < vec.len() {
if f(&mut vec[i]) {
i += 1;
} else {
vec.swap_remove(i);
}
}
}

0 comments on commit 8cf12c5

Please sign in to comment.