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()); let listener = EventListenerType::Additive(listener.clone());
if let Some(entries) = handlers.get_mut(ty) { 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 * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![feature(drain_filter)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(plugin)] #![feature(plugin)]
#![feature(register_tool)] #![feature(register_tool)]

View file

@ -120,23 +120,29 @@ impl<T: QueuedTaskConversion> TaskQueue<T> {
} }
// 4. Filter tasks from non-priority task-sources. // 4. Filter tasks from non-priority task-sources.
let to_be_throttled: Vec<T> = incoming // TODO: This can use `extract_if` once that is stabilized.
.drain_filter(|msg| { let mut to_be_throttled = Vec::new();
let task_source = match msg.task_source_name() { 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, Some(task_source) => task_source,
None => return false, None => continue,
}; };
match task_source { match task_source {
TaskSourceName::PerformanceTimeline => return true, 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" // A task that will not be throttled, start counting "business"
self.taken_task_counter self.taken_task_counter
.set(self.taken_task_counter.get() + 1); .set(self.taken_task_counter.get() + 1);
return false;
}, },
} }
}) }
.collect();
for msg in incoming { for msg in incoming {
if let Some(pipeline_id) = msg.pipeline_id() { if let Some(pipeline_id) = msg.pipeline_id() {