Skip to content

Commit

Permalink
move retain_unordered_mut function into parallel module
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Jan 29, 2024
1 parent 6320cf3 commit cb04126
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
20 changes: 1 addition & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ impl Build {

cell_update(&pendings, |mut pendings| {
// Try waiting on them.
retain_unordered_mut(&mut pendings, |(cmd, program, child, _token)| {
parallel::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 @@ -4344,21 +4344,3 @@ 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);
}
}
}
17 changes: 17 additions & 0 deletions src/parallel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
pub(crate) mod async_executor;
pub(crate) mod job_token;

/// Remove all element in `vec` which `f(element)` returns `false`.
///
/// TODO: Remove this once the MSRV is bumped to v1.61
pub(crate) 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 cb04126

Please sign in to comment.