From 17a1dd938544a54b7457a42246872ebba1ec9bd5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 7 Sep 2017 14:38:53 +0200 Subject: =?UTF-8?q?Kill=20Runnable::is=5Fcancelled=20=E2=9A=94=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/script/script_thread.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'components/script/script_thread.rs') 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 { inner: Box, } -impl Runnable for CancellableRunnable { +impl CancellableRunnable +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 Runnable for CancellableRunnable +where + T: Runnable + Send, +{ fn main_thread_handler(self: Box>, 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>) { - 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::() } } fn handler(self: Box) {} fn main_thread_handler(self: Box, _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), -- cgit v1.2.3