diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2018-02-21 17:28:12 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2018-02-21 17:28:12 +0100 |
commit | eb83826c01138dae88bf56080e6ec7891e6201fe (patch) | |
tree | 12da5ba8a77e106f8ac6cc9732a211f77e23dc96 /components | |
parent | 4d7383f4f3acabfdc76c285c8cf7fb849abd11bd (diff) | |
download | servo-eb83826c01138dae88bf56080e6ec7891e6201fe.tar.gz servo-eb83826c01138dae88bf56080e6ec7891e6201fe.zip |
Avoid dropping arbitrary animation callbacks without running them
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/document.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index abe67fc343f..7f7bc4fd272 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1485,10 +1485,18 @@ impl Document { // constellation to stop giving us video refresh callbacks, to save energy. (A spurious // animation frame is one in which the callback did not mutate the DOM—that is, an // animation frame that wasn't actually used for animation.) - if self.animation_frame_list.borrow().is_empty() || - (!was_faking_animation_frames && self.is_faking_animation_frames()) { - mem::swap(&mut *self.animation_frame_list.borrow_mut(), - &mut *animation_frame_list); + let is_empty = self.animation_frame_list.borrow().is_empty(); + if is_empty || (!was_faking_animation_frames && self.is_faking_animation_frames()) { + if is_empty { + // If the current animation frame list in the DOM instance is empty, + // we can reuse the original `Vec<T>` that we put on the stack to + // avoid allocating a new one next time an animation callback + // is queued. + mem::swap( + &mut *self.animation_frame_list.borrow_mut(), + &mut *animation_frame_list, + ); + } let event = ScriptMsg::ChangeRunningAnimationsState(AnimationState::NoAnimationCallbacksPresent); self.send_to_constellation(event); } |