Skip to content

Commit dca5295

Browse files
committed
use stable extract_if: since 1.87
1 parent ee0b821 commit dca5295

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

site/src/job_queue.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,6 @@ fn sort_benchmark_requests(done: &HashSet<String>, request_queue: &mut [Benchmar
9595
}
9696
}
9797

98-
pub trait ExtractIf<T> {
99-
fn extract_if_stable<F>(&mut self, predicate: F) -> Vec<T>
100-
where
101-
F: FnMut(&T) -> bool;
102-
}
103-
104-
/// Vec method `extract_if` is unstable, this very simple implementation
105-
/// can be deleted once it is stable
106-
impl<T> ExtractIf<T> for Vec<T> {
107-
fn extract_if_stable<F>(&mut self, mut predicate: F) -> Vec<T>
108-
where
109-
F: FnMut(&T) -> bool,
110-
{
111-
let mut extracted = Vec::new();
112-
let mut i = 0;
113-
114-
while i < self.len() {
115-
if predicate(&self[i]) {
116-
extracted.push(self.remove(i));
117-
} else {
118-
i += 1;
119-
}
120-
}
121-
extracted
122-
}
123-
}
124-
12598
/// Assumes that master/release artifacts have been put into the DB.
12699
pub async fn build_queue(
127100
conn: &mut dyn database::pool::Connection,
@@ -136,15 +109,20 @@ pub async fn build_queue(
136109

137110
// The queue starts with in progress
138111
let mut queue: Vec<BenchmarkRequest> = pending
139-
.extract_if_stable(|request| matches!(request.status, BenchmarkRequestStatus::InProgress));
112+
.extract_if(.., |request| {
113+
matches!(request.status, BenchmarkRequestStatus::InProgress)
114+
})
115+
.collect();
140116

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

144120
// Add release artifacts ordered by the release tag (1.87.0 before 1.88.0) and `created_at`.
145-
let mut release_artifacts: Vec<BenchmarkRequest> = pending.extract_if_stable(|request| {
146-
matches!(request.commit_type, BenchmarkRequestType::Release { .. })
147-
});
121+
let mut release_artifacts: Vec<BenchmarkRequest> = pending
122+
.extract_if(.., |request| {
123+
matches!(request.commit_type, BenchmarkRequestType::Release { .. })
124+
})
125+
.collect();
148126

149127
release_artifacts.sort_unstable_by(|a, b| {
150128
a.tag()

0 commit comments

Comments
 (0)