Skip to content

use stable extract_if: since 1.87 #2191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 9 additions & 31 deletions site/src/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,6 @@ fn sort_benchmark_requests(done: &HashSet<String>, request_queue: &mut [Benchmar
}
}

pub trait ExtractIf<T> {
fn extract_if_stable<F>(&mut self, predicate: F) -> Vec<T>
where
F: FnMut(&T) -> bool;
}

/// Vec method `extract_if` is unstable, this very simple implementation
/// can be deleted once it is stable
impl<T> ExtractIf<T> for Vec<T> {
fn extract_if_stable<F>(&mut self, mut predicate: F) -> Vec<T>
where
F: FnMut(&T) -> bool,
{
let mut extracted = Vec::new();
let mut i = 0;

while i < self.len() {
if predicate(&self[i]) {
extracted.push(self.remove(i));
} else {
i += 1;
}
}
extracted
}
}

/// Assumes that master/release artifacts have been put into the DB.
pub async fn build_queue(
conn: &mut dyn database::pool::Connection,
Expand All @@ -136,15 +109,20 @@ pub async fn build_queue(

// The queue starts with in progress
let mut queue: Vec<BenchmarkRequest> = pending
.extract_if_stable(|request| matches!(request.status, BenchmarkRequestStatus::InProgress));
.extract_if(.., |request| {
matches!(request.status, BenchmarkRequestStatus::InProgress)
})
.collect();

// We sort the in-progress ones based on the started date
queue.sort_unstable_by(|a, b| a.created_at.cmp(&b.created_at));

// Add release artifacts ordered by the release tag (1.87.0 before 1.88.0) and `created_at`.
let mut release_artifacts: Vec<BenchmarkRequest> = pending.extract_if_stable(|request| {
matches!(request.commit_type, BenchmarkRequestType::Release { .. })
});
let mut release_artifacts: Vec<BenchmarkRequest> = pending
.extract_if(.., |request| {
matches!(request.commit_type, BenchmarkRequestType::Release { .. })
})
.collect();

release_artifacts.sort_unstable_by(|a, b| {
a.tag()
Expand Down
Loading