Skip to content

Commit

Permalink
use a vec for pending resize and compositor events
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed May 7, 2024
1 parent 9410aeb commit cc68cd7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub struct Document {
/// Pending composition events, to be handled at the next rendering opportunity.
#[no_trace]
#[ignore_malloc_size_of = "CompositorEvent contains data from outside crates"]
pending_compositor_events: DomRefCell<VecDeque<CompositorEvent>>,
pending_compositor_events: DomRefCell<Vec<CompositorEvent>>,
/// The index of the last mouse move event in the pending compositor events queue.
mouse_move_event_index: DomRefCell<Option<usize>>,
/// Pending animation ticks, to be handled at the next rendering opportunity.
Expand Down Expand Up @@ -3264,11 +3264,11 @@ impl Document {
Some(self.pending_compositor_events.borrow().len());
}

self.pending_compositor_events.borrow_mut().push_back(event);
self.pending_compositor_events.borrow_mut().push(event);
}

/// Get pending compositor events, for processing within an `update_the_rendering` task.
pub fn take_pending_compositor_events(&self) -> VecDeque<CompositorEvent> {
pub fn take_pending_compositor_events(&self) -> Vec<CompositorEvent> {
// Reset the mouse event index.
*self.mouse_move_event_index.borrow_mut() = None;
mem::take(&mut *self.pending_compositor_events.borrow_mut())
Expand Down
10 changes: 4 additions & 6 deletions components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::borrow::{Cow, ToOwned};
use std::cell::Cell;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::io::{stderr, stdout, Write};
use std::ptr::NonNull;
Expand Down Expand Up @@ -222,7 +222,7 @@ pub struct Window {

/// Pending resize events, if any.
#[no_trace]
resize_events: DomRefCell<VecDeque<(WindowSizeData, WindowSizeType)>>,
resize_events: DomRefCell<Vec<(WindowSizeData, WindowSizeType)>>,

/// Parent id associated with this page, if any.
#[no_trace]
Expand Down Expand Up @@ -2329,12 +2329,10 @@ impl Window {
}

pub fn add_resize_event(&self, event: WindowSizeData, event_type: WindowSizeType) {
self.resize_events
.borrow_mut()
.push_back((event, event_type));
self.resize_events.borrow_mut().push((event, event_type));
}

pub fn steal_resize_events(&self) -> VecDeque<(WindowSizeData, WindowSizeType)> {
pub fn steal_resize_events(&self) -> Vec<(WindowSizeData, WindowSizeType)> {
mem::take(&mut self.resize_events.borrow_mut())
}

Expand Down
3 changes: 1 addition & 2 deletions components/script/script_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,7 @@ impl ScriptThread {
// TODO(#31665): Implement the "run the scroll steps" from
// https://drafts.csswg.org/cssom-view/#document-run-the-scroll-steps.

let mut pending_resize_events = document.window().steal_resize_events();
while let Some((size, size_type)) = pending_resize_events.pop_front() {
for (size, size_type) in document.window().steal_resize_events().into_iter() {
// Resize steps.
self.run_the_resize_steps(pipeline_id, size, size_type);

Expand Down

0 comments on commit cc68cd7

Please sign in to comment.