Remove usage of drain_filter (#30742)

This is a step on the way toward supporting stable rust.
This commit is contained in:
Martin Robinson 2023-11-17 11:28:33 +01:00 committed by GitHub
parent 50732b49c5
commit 8de4629a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View file

@ -448,7 +448,7 @@ impl EventTarget {
let listener = EventListenerType::Additive(listener.clone());
if let Some(entries) = handlers.get_mut(ty) {
entries.drain_filter(|e| e.listener == listener && e.once);
entries.retain(|e| e.listener != listener || !e.once)
}
}

View file

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![feature(drain_filter)]
#![feature(once_cell)]
#![feature(plugin)]
#![feature(register_tool)]

View file

@ -120,23 +120,29 @@ impl<T: QueuedTaskConversion> TaskQueue<T> {
}
// 4. Filter tasks from non-priority task-sources.
let to_be_throttled: Vec<T> = incoming
.drain_filter(|msg| {
let task_source = match msg.task_source_name() {
Some(task_source) => task_source,
None => return false,
};
match task_source {
TaskSourceName::PerformanceTimeline => return true,
_ => {
// A task that will not be throttled, start counting "business"
self.taken_task_counter
.set(self.taken_task_counter.get() + 1);
return false;
},
}
})
.collect();
// TODO: This can use `extract_if` once that is stabilized.
let mut to_be_throttled = Vec::new();
let mut index = 0;
while index != incoming.len() {
index += 1; // By default we go to the next index of the vector.
let task_source = match incoming[index - 1].task_source_name() {
Some(task_source) => task_source,
None => continue,
};
match task_source {
TaskSourceName::PerformanceTimeline => {
to_be_throttled.push(incoming.remove(index - 1));
index -= 1; // We've removed an element, so the next has the same index.
},
_ => {
// A task that will not be throttled, start counting "business"
self.taken_task_counter
.set(self.taken_task_counter.get() + 1);
},
}
}
for msg in incoming {
if let Some(pipeline_id) = msg.pipeline_id() {