From b0d1cde558a0ecb8517974f8ef31c7d4f8b65770 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 19 Sep 2017 10:19:49 -0700 Subject: [PATCH] Make the thread_state machinery behave the same across debug and opt builds. I don't need this per se, but it seems like a footgun for the methods to return incorrect information depending on the build type. I don't see anywhere where the overhead would be at all significant. MozReview-Commit-ID: G1qyUFhI0aB --- components/style/thread_state.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/components/style/thread_state.rs b/components/style/thread_state.rs index ab0672e2503..035d1e939b8 100644 --- a/components/style/thread_state.rs +++ b/components/style/thread_state.rs @@ -2,11 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -//! Supports dynamic assertions in debug builds about what sort of thread is -//! running and what state it's in. -//! -//! In release builds, `get` returns 0. All of the other functions inline -//! away to nothing. +//! Supports dynamic assertions in about what sort of thread is running and +//! what state it's in. #![deny(missing_docs)] @@ -37,20 +34,13 @@ macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( } $( - #[cfg(debug_assertions)] #[allow(missing_docs)] pub fn $fun(self) -> bool { self.contains($flag) } - #[cfg(not(debug_assertions))] - #[allow(missing_docs)] - pub fn $fun(self) -> bool { - true - } )* } - #[cfg(debug_assertions)] static TYPES: &'static [ThreadState] = &[ $( $flag ),* ]; )); @@ -60,7 +50,6 @@ thread_types! { is_layout = LAYOUT; } -#[cfg(debug_assertions)] mod imp { use std::cell::RefCell; use super::{TYPES, ThreadState}; @@ -89,14 +78,14 @@ mod imp { }); // Exactly one of the thread type flags should be set. - assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count()); + debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count()); state } /// Enter into a given temporary state. Panics if re-entring. pub fn enter(x: ThreadState) { let state = get(); - assert!(!state.intersects(x)); + debug_assert!(!state.intersects(x)); STATE.with(|ref k| { *k.borrow_mut() = Some(state | x); }) @@ -105,19 +94,9 @@ mod imp { /// Exit a given temporary state. pub fn exit(x: ThreadState) { let state = get(); - assert!(state.contains(x)); + debug_assert!(state.contains(x)); STATE.with(|ref k| { *k.borrow_mut() = Some(state & !x); }) } } - -#[cfg(not(debug_assertions))] -#[allow(missing_docs)] -mod imp { - use super::ThreadState; - #[inline(always)] pub fn initialize(_: ThreadState) { } - #[inline(always)] pub fn get() -> ThreadState { ThreadState::empty() } - #[inline(always)] pub fn enter(_: ThreadState) { } - #[inline(always)] pub fn exit(_: ThreadState) { } -}