diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-07 14:38:53 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-07 14:54:03 +0200 |
commit | 17a1dd938544a54b7457a42246872ebba1ec9bd5 (patch) | |
tree | 3ec847f85f2036d2288fa1c62462023b7f0e177d /components/script/script_thread.rs | |
parent | c68bc0c145db3ce2df49023c1525dbfc7d252153 (diff) | |
download | servo-17a1dd938544a54b7457a42246872ebba1ec9bd5.tar.gz servo-17a1dd938544a54b7457a42246872ebba1ec9bd5.zip |
Kill Runnable::is_cancelled ⚔️
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index cfd7715994b..a576af4407e 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -221,24 +221,35 @@ pub struct CancellableRunnable<T: Runnable + Send> { 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(); } @@ -1281,12 +1292,7 @@ impl ScriptThread { 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), |