servo: Merge #18407 - Kill Runnable::is_cancelled ⚔️ (from servo:kill-is-cancelled); r=emilio
authorAnthony Ramine <n.oxyde@gmail.com>
Thu, 07 Sep 2017 14:53:35 -0500
changeset 429059 f8bfb757632da365e6bc35c9f066573a75f82d7f
parent 429058 3a39f8baf4ecfb635cb92da56054970985f8e98b
child 429060 1b2b3bc1d47b27d02c7187c818a7f5f5808ddc1f
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs18407
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #18407 - Kill Runnable::is_cancelled ⚔️ (from servo:kill-is-cancelled); r=emilio Source-Repo: https://github.com/servo/servo Source-Revision: 867a982fa71b26cec3788e1c825dd9addb9725f9
servo/components/script/script_thread.rs
servo/components/script/task_source/dom_manipulation.rs
servo/components/script/task_source/user_interaction.rs
--- a/servo/components/script/script_thread.rs
+++ b/servo/components/script/script_thread.rs
@@ -216,34 +216,45 @@ impl RunnableWrapper {
 }
 
 /// A runnable that can be discarded by toggling a shared flag.
 pub struct CancellableRunnable<T: Runnable + Send> {
     cancelled: Option<Arc<AtomicBool>>,
     inner: Box<T>,
 }
 
-impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
+impl<T> CancellableRunnable<T>
+where
+    T: Runnable + Send,
+{
     fn is_cancelled(&self) -> bool {
-        self.cancelled.as_ref()
-            .map(|cancelled| cancelled.load(Ordering::SeqCst))
-            .unwrap_or(false)
+        self.cancelled.as_ref().map_or(false, |cancelled| {
+            cancelled.load(Ordering::SeqCst)
+        })
     }
+}
 
+impl<T> Runnable for CancellableRunnable<T>
+where
+    T: Runnable + Send,
+{
     fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) {
-        self.inner.main_thread_handler(script_thread);
+        if !self.is_cancelled() {
+            self.inner.main_thread_handler(script_thread);
+        }
     }
 
     fn handler(self: Box<CancellableRunnable<T>>) {
-        self.inner.handler()
+        if !self.is_cancelled() {
+            self.inner.handler()
+        }
     }
 }
 
 pub trait Runnable {
-    fn is_cancelled(&self) -> bool { false }
     fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
     fn handler(self: Box<Self>) {}
     fn main_thread_handler(self: Box<Self>, _script_thread: &ScriptThread) { self.handler(); }
 }
 
 #[derive(Debug)]
 enum MixedMessage {
     FromConstellation(ConstellationControlMsg),
@@ -1276,22 +1287,17 @@ impl ScriptThread {
         match msg {
             MainThreadScriptMsg::Navigate(parent_pipeline_id, load_data, replace) =>
                 self.handle_navigate(parent_pipeline_id, None, load_data, replace),
             MainThreadScriptMsg::ExitWindow(id) =>
                 self.handle_exit_window_msg(id),
             MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
                 // The category of the runnable is ignored by the pattern, however
                 // it is still respected by profiling (see categorize_msg).
-                if !runnable.is_cancelled() {
-                    debug!("Running runnable.");
-                    runnable.main_thread_handler(self)
-                } else {
-                    debug!("Not running cancelled runnable.");
-                }
+                runnable.main_thread_handler(self)
             }
             MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) =>
                 self.collect_reports(reports_chan),
             MainThreadScriptMsg::WorkletLoaded(pipeline_id) =>
                 self.handle_worklet_loaded(pipeline_id),
             MainThreadScriptMsg::DOMManipulation(task) =>
                 task.handle_task(self),
             MainThreadScriptMsg::UserInteraction(task) =>
--- a/servo/components/script/task_source/dom_manipulation.rs
+++ b/servo/components/script/task_source/dom_manipulation.rs
@@ -66,13 +66,11 @@ pub struct DOMManipulationTask(pub Box<R
 impl fmt::Debug for DOMManipulationTask {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "DOMManipulationTask(...)")
     }
 }
 
 impl DOMManipulationTask {
     pub fn handle_task(self, script_thread: &ScriptThread) {
-        if !self.0.is_cancelled() {
-            self.0.main_thread_handler(script_thread);
-        }
+        self.0.main_thread_handler(script_thread);
     }
 }
--- a/servo/components/script/task_source/user_interaction.rs
+++ b/servo/components/script/task_source/user_interaction.rs
@@ -57,13 +57,11 @@ pub struct UserInteractionTask(pub Box<R
 impl fmt::Debug for UserInteractionTask {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "UserInteractionTask(...)")
     }
 }
 
 impl UserInteractionTask {
     pub fn handle_task(self, script_thread: &ScriptThread) {
-        if !self.0.is_cancelled() {
-            self.0.main_thread_handler(script_thread);
-        }
+        self.0.main_thread_handler(script_thread);
     }
 }