style: Use Default for ExtraStyleData instead of Option.

This commit is contained in:
Emilio Cobos Álvarez 2018-01-12 11:04:24 +01:00
parent 9a1f20f1e8
commit 335ca47361
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 18 additions and 13 deletions

View file

@ -131,7 +131,7 @@ where
pub pseudo_element_matching_fn: Option<&'a Fn(&Impl::PseudoElement) -> bool>, pub pseudo_element_matching_fn: Option<&'a Fn(&Impl::PseudoElement) -> bool>,
/// Extra implementation-dependent matching data. /// Extra implementation-dependent matching data.
pub extra_data: Option<Impl::ExtraMatchingData>, pub extra_data: Impl::ExtraMatchingData,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
classes_and_ids_case_sensitivity: CaseSensitivity, classes_and_ids_case_sensitivity: CaseSensitivity,
@ -176,7 +176,7 @@ where
scope_element: None, scope_element: None,
nesting_level: 0, nesting_level: 0,
pseudo_element_matching_fn: None, pseudo_element_matching_fn: None,
extra_data: None, extra_data: Default::default(),
_impl: ::std::marker::PhantomData, _impl: ::std::marker::PhantomData,
} }
} }

View file

@ -84,7 +84,7 @@ macro_rules! with_all_bounds {
/// are parameterized on SelectorImpl. See /// are parameterized on SelectorImpl. See
/// <https://github.com/rust-lang/rust/issues/26925> /// <https://github.com/rust-lang/rust/issues/26925>
pub trait SelectorImpl: Clone + Sized + 'static { pub trait SelectorImpl: Clone + Sized + 'static {
type ExtraMatchingData: Sized + 'static; type ExtraMatchingData: Sized + Default + 'static;
type AttrValue: $($InSelector)*; type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)* + PrecomputedHash; type Identifier: $($InSelector)* + PrecomputedHash;
type ClassName: $($InSelector)* + PrecomputedHash; type ClassName: $($InSelector)* + PrecomputedHash;

View file

@ -2111,10 +2111,8 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
} }
NonTSPseudoClass::MozWindowInactive => { NonTSPseudoClass::MozWindowInactive => {
let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE; let state_bit = DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE;
if let Some(ref invalidation_data) = context.extra_data { if context.extra_data.document_state.intersects(state_bit) {
if invalidation_data.document_state.intersects(state_bit) { return true;
return true;
}
} }
self.document_state().contains(state_bit) self.document_state().contains(state_bit)
@ -2133,12 +2131,10 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
} }
NonTSPseudoClass::MozLocaleDir(ref dir) => { NonTSPseudoClass::MozLocaleDir(ref dir) => {
let state_bit = DocumentState::NS_DOCUMENT_STATE_RTL_LOCALE; 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 // NOTE(emilio): We could still return false for
// Direction::Other(..), but we don't bother. // 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); let doc_is_rtl = self.document_state().contains(state_bit);

View file

@ -19,6 +19,15 @@ pub struct InvalidationMatchingData {
pub document_state: DocumentState, 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 /// An invalidation processor for style changes due to state and attribute
/// changes. /// changes.
pub struct DocumentStateInvalidationProcessor<'a, E: TElement> { pub struct DocumentStateInvalidationProcessor<'a, E: TElement> {
@ -46,9 +55,9 @@ impl<'a, E: TElement> DocumentStateInvalidationProcessor<'a, E> {
quirks_mode, quirks_mode,
); );
matching_context.extra_data = Some(InvalidationMatchingData { matching_context.extra_data = InvalidationMatchingData {
document_state: document_states_changed, document_state: document_states_changed,
}); };
Self { rules, document_states_changed, matching_context } Self { rules, document_states_changed, matching_context }
} }