From 335ca47361dc6837f8ef72fb3f738b1c1005499b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 12 Jan 2018 11:04:24 +0100 Subject: [PATCH] style: Use Default for ExtraStyleData instead of Option. --- components/selectors/context.rs | 4 ++-- components/selectors/parser.rs | 2 +- components/style/gecko/wrapper.rs | 12 ++++-------- .../style/invalidation/element/document_state.rs | 13 +++++++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/selectors/context.rs b/components/selectors/context.rs index 79e0b69b4e8..856e18497d9 100644 --- a/components/selectors/context.rs +++ b/components/selectors/context.rs @@ -131,7 +131,7 @@ where pub pseudo_element_matching_fn: Option<&'a Fn(&Impl::PseudoElement) -> bool>, /// Extra implementation-dependent matching data. - pub extra_data: Option, + pub extra_data: Impl::ExtraMatchingData, quirks_mode: QuirksMode, classes_and_ids_case_sensitivity: CaseSensitivity, @@ -176,7 +176,7 @@ where scope_element: None, nesting_level: 0, pseudo_element_matching_fn: None, - extra_data: None, + extra_data: Default::default(), _impl: ::std::marker::PhantomData, } } diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index dead7875d0f..99b73353abf 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -84,7 +84,7 @@ macro_rules! with_all_bounds { /// are parameterized on SelectorImpl. See /// pub trait SelectorImpl: Clone + Sized + 'static { - type ExtraMatchingData: Sized + 'static; + type ExtraMatchingData: Sized + Default + 'static; type AttrValue: $($InSelector)*; type Identifier: $($InSelector)* + PrecomputedHash; type ClassName: $($InSelector)* + PrecomputedHash; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 4de36a327d4..a2f75c4b4bb 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -2111,10 +2111,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { } NonTSPseudoClass::MozWindowInactive => { let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE; - if let Some(ref invalidation_data) = context.extra_data { - if invalidation_data.document_state.intersects(state_bit) { - return true; - } + if context.extra_data.document_state.intersects(state_bit) { + return true; } self.document_state().contains(state_bit) @@ -2133,12 +2131,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { } NonTSPseudoClass::MozLocaleDir(ref dir) => { let state_bit = DocumentState::NS_DOCUMENT_STATE_RTL_LOCALE; - if let Some(ref invalidation_data) = context.extra_data { + if context.extra_data.document_state.intersects(state_bit) { // NOTE(emilio): We could still return false for // Direction::Other(..), but we don't bother. - if invalidation_data.document_state.intersects(state_bit) { - return true; - } + return true; } let doc_is_rtl = self.document_state().contains(state_bit); diff --git a/components/style/invalidation/element/document_state.rs b/components/style/invalidation/element/document_state.rs index f7a8926b8c3..cf7a164ebdb 100644 --- a/components/style/invalidation/element/document_state.rs +++ b/components/style/invalidation/element/document_state.rs @@ -19,6 +19,15 @@ pub struct InvalidationMatchingData { pub document_state: DocumentState, } +impl Default for InvalidationMatchingData { + #[inline(always)] + fn default() -> Self { + Self { + document_state: DocumentState::empty(), + } + } +} + /// An invalidation processor for style changes due to state and attribute /// changes. pub struct DocumentStateInvalidationProcessor<'a, E: TElement> { @@ -46,9 +55,9 @@ impl<'a, E: TElement> DocumentStateInvalidationProcessor<'a, E> { quirks_mode, ); - matching_context.extra_data = Some(InvalidationMatchingData { + matching_context.extra_data = InvalidationMatchingData { document_state: document_states_changed, - }); + }; Self { rules, document_states_changed, matching_context } }