diff options
author | Martin Robinson <mrobinson@igalia.com> | 2023-11-17 11:28:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 10:28:33 +0000 |
commit | 8de4629a3c769e78c47a163326f045ca53ed6298 (patch) | |
tree | e34206d65b450047f1ae5a41f334a1ddcd031d1a /components/script/task_queue.rs | |
parent | 50732b49c5ad3937cf2b8f94e86a9efa1f2ce4de (diff) | |
download | servo-8de4629a3c769e78c47a163326f045ca53ed6298.tar.gz servo-8de4629a3c769e78c47a163326f045ca53ed6298.zip |
Remove usage of `drain_filter` (#30742)
This is a step on the way toward supporting stable rust.
Diffstat (limited to 'components/script/task_queue.rs')
-rw-r--r-- | components/script/task_queue.rs | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/components/script/task_queue.rs b/components/script/task_queue.rs index 38acc7ed04b..bb58dea8ab1 100644 --- a/components/script/task_queue.rs +++ b/components/script/task_queue.rs @@ -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() { |