mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Avoid generic soup and extra reference count bumps
This makes me a bit happier about the previous patch :) Differential Revision: https://phabricator.services.mozilla.com/D165236
This commit is contained in:
parent
cceb538eb0
commit
92742f7f90
7 changed files with 32 additions and 24 deletions
|
@ -145,7 +145,7 @@ where
|
||||||
pub pseudo_element_matching_fn: Option<&'a dyn Fn(&Impl::PseudoElement) -> bool>,
|
pub pseudo_element_matching_fn: Option<&'a dyn Fn(&Impl::PseudoElement) -> bool>,
|
||||||
|
|
||||||
/// Extra implementation-dependent matching data.
|
/// Extra implementation-dependent matching data.
|
||||||
pub extra_data: Impl::ExtraMatchingData,
|
pub extra_data: Impl::ExtraMatchingData<'a>,
|
||||||
|
|
||||||
quirks_mode: QuirksMode,
|
quirks_mode: QuirksMode,
|
||||||
needs_selector_flags: NeedsSelectorFlags,
|
needs_selector_flags: NeedsSelectorFlags,
|
||||||
|
|
|
@ -202,7 +202,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 + Debug + Sized + 'static {
|
pub trait SelectorImpl: Clone + Debug + Sized + 'static {
|
||||||
type ExtraMatchingData: Sized + Default + 'static;
|
type ExtraMatchingData<'a>: Sized + Default;
|
||||||
type AttrValue: $($InSelector)*;
|
type AttrValue: $($InSelector)*;
|
||||||
type Identifier: $($InSelector)*;
|
type Identifier: $($InSelector)*;
|
||||||
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName>;
|
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName>;
|
||||||
|
@ -2638,7 +2638,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectorImpl for DummySelectorImpl {
|
impl SelectorImpl for DummySelectorImpl {
|
||||||
type ExtraMatchingData = ();
|
type ExtraMatchingData<'a> = std::marker::PhantomData<&'a ()>;
|
||||||
type AttrValue = DummyAttrValue;
|
type AttrValue = DummyAttrValue;
|
||||||
type Identifier = DummyAtom;
|
type Identifier = DummyAtom;
|
||||||
type LocalName = DummyAtom;
|
type LocalName = DummyAtom;
|
||||||
|
|
|
@ -18,7 +18,6 @@ use cssparser::{CowRcStr, SourceLocation, ToCss, Token};
|
||||||
use dom::{DocumentState, ElementState};
|
use dom::{DocumentState, ElementState};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use selectors::SelectorList;
|
use selectors::SelectorList;
|
||||||
use servo_arc::Arc;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_};
|
||||||
|
|
||||||
|
@ -236,7 +235,7 @@ pub struct SelectorImpl;
|
||||||
/// A set of extra data to carry along with the matching context, either for
|
/// A set of extra data to carry along with the matching context, either for
|
||||||
/// selector-matching or invalidation.
|
/// selector-matching or invalidation.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ExtraMatchingData {
|
pub struct ExtraMatchingData<'a> {
|
||||||
/// The invalidation data to invalidate doc-state pseudo-classes correctly.
|
/// The invalidation data to invalidate doc-state pseudo-classes correctly.
|
||||||
pub invalidation_data: InvalidationMatchingData,
|
pub invalidation_data: InvalidationMatchingData,
|
||||||
|
|
||||||
|
@ -246,11 +245,11 @@ pub struct ExtraMatchingData {
|
||||||
|
|
||||||
/// The style of the originating element in order to evaluate @container
|
/// The style of the originating element in order to evaluate @container
|
||||||
/// size queries affecting pseudo-elements.
|
/// size queries affecting pseudo-elements.
|
||||||
pub originating_element_style: Option<Arc<ComputedValues>>,
|
pub originating_element_style: Option<&'a ComputedValues>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::selectors::SelectorImpl for SelectorImpl {
|
impl ::selectors::SelectorImpl for SelectorImpl {
|
||||||
type ExtraMatchingData = ExtraMatchingData;
|
type ExtraMatchingData<'a> = ExtraMatchingData<'a>;
|
||||||
type AttrValue = AtomString;
|
type AttrValue = AtomString;
|
||||||
type Identifier = AtomIdent;
|
type Identifier = AtomIdent;
|
||||||
type LocalName = AtomIdent;
|
type LocalName = AtomIdent;
|
||||||
|
|
|
@ -103,6 +103,15 @@ impl ComputedValues {
|
||||||
).to_outer(None)
|
).to_outer(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts the computed values to an Arc<> from a reference.
|
||||||
|
pub fn to_arc(&self) -> Arc<Self> {
|
||||||
|
// SAFETY: We're guaranteed to be allocated as an Arc<> since the
|
||||||
|
// functions above are the only ones that create ComputedValues
|
||||||
|
// instances in Gecko (and that must be the case since ComputedValues'
|
||||||
|
// member is private).
|
||||||
|
unsafe { Arc::from_raw_addrefed(self) }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_pseudo_style(&self) -> bool {
|
pub fn is_pseudo_style(&self) -> bool {
|
||||||
self.0.mPseudoType != PseudoStyleType::NotPseudo
|
self.0.mPseudoType != PseudoStyleType::NotPseudo
|
||||||
|
@ -208,8 +217,8 @@ impl ComputedValuesInner {
|
||||||
&self,
|
&self,
|
||||||
pseudo_ty,
|
pseudo_ty,
|
||||||
);
|
);
|
||||||
// We're simulating move semantics by having C++ do a memcpy and then forgetting
|
// We're simulating move semantics by having C++ do a memcpy and
|
||||||
// it on this end.
|
// then forgetting it on this end.
|
||||||
forget(self);
|
forget(self);
|
||||||
UniqueArc::assume_init(arc).shareable()
|
UniqueArc::assume_init(arc).shareable()
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,7 +507,7 @@ where
|
||||||
|
|
||||||
fn match_pseudo(
|
fn match_pseudo(
|
||||||
&mut self,
|
&mut self,
|
||||||
originating_element_style: &Arc<ComputedValues>,
|
originating_element_style: &ComputedValues,
|
||||||
pseudo_element: &PseudoElement,
|
pseudo_element: &PseudoElement,
|
||||||
visited_handling: VisitedHandlingMode,
|
visited_handling: VisitedHandlingMode,
|
||||||
) -> Option<MatchingResults> {
|
) -> Option<MatchingResults> {
|
||||||
|
@ -544,7 +544,7 @@ where
|
||||||
NeedsSelectorFlags::Yes,
|
NeedsSelectorFlags::Yes,
|
||||||
);
|
);
|
||||||
matching_context.extra_data.originating_element_style =
|
matching_context.extra_data.originating_element_style =
|
||||||
Some(originating_element_style.clone());
|
Some(originating_element_style);
|
||||||
|
|
||||||
// NB: We handle animation rules for ::before and ::after when
|
// NB: We handle animation rules for ::before and ::after when
|
||||||
// traversing them.
|
// traversing them.
|
||||||
|
|
|
@ -135,14 +135,14 @@ enum TraversalResult<T> {
|
||||||
Done(T),
|
Done(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traverse_container<E, S, F, R>(
|
fn traverse_container<E, F, R>(
|
||||||
mut e: E,
|
mut e: E,
|
||||||
originating_element_style: Option<&S>,
|
originating_element_style: Option<&ComputedValues>,
|
||||||
evaluator: F,
|
evaluator: F,
|
||||||
) -> Option<(E, R)>
|
) -> Option<(E, R)>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
F: Fn(E, Option<&S>) -> TraversalResult<R>,
|
F: Fn(E, Option<&ComputedValues>) -> TraversalResult<R>,
|
||||||
{
|
{
|
||||||
if originating_element_style.is_some() {
|
if originating_element_style.is_some() {
|
||||||
match evaluator(e, originating_element_style) {
|
match evaluator(e, originating_element_style) {
|
||||||
|
@ -185,7 +185,7 @@ impl ContainerCondition {
|
||||||
fn valid_container_info<E>(
|
fn valid_container_info<E>(
|
||||||
&self,
|
&self,
|
||||||
potential_container: E,
|
potential_container: E,
|
||||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
originating_element_style: Option<&ComputedValues>,
|
||||||
) -> TraversalResult<ContainerLookupResult<E>>
|
) -> TraversalResult<ContainerLookupResult<E>>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
|
@ -198,7 +198,7 @@ impl ContainerCondition {
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => return TraversalResult::InProgress,
|
None => return TraversalResult::InProgress,
|
||||||
};
|
};
|
||||||
data.styles.primary()
|
&**data.styles.primary()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let wm = style.writing_mode;
|
let wm = style.writing_mode;
|
||||||
|
@ -220,7 +220,7 @@ impl ContainerCondition {
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = potential_container.query_container_size(&box_style.clone_display());
|
let size = potential_container.query_container_size(&box_style.clone_display());
|
||||||
let style = style.clone();
|
let style = style.to_arc();
|
||||||
TraversalResult::Done(ContainerLookupResult {
|
TraversalResult::Done(ContainerLookupResult {
|
||||||
element: potential_container,
|
element: potential_container,
|
||||||
info: ContainerInfo { size, wm },
|
info: ContainerInfo { size, wm },
|
||||||
|
@ -232,7 +232,7 @@ impl ContainerCondition {
|
||||||
pub fn find_container<E>(
|
pub fn find_container<E>(
|
||||||
&self,
|
&self,
|
||||||
e: E,
|
e: E,
|
||||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
originating_element_style: Option<&ComputedValues>,
|
||||||
) -> Option<ContainerLookupResult<E>>
|
) -> Option<ContainerLookupResult<E>>
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
|
@ -254,7 +254,7 @@ impl ContainerCondition {
|
||||||
&self,
|
&self,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
element: E,
|
element: E,
|
||||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
originating_element_style: Option<&ComputedValues>,
|
||||||
invalidation_flags: &mut ComputedValueFlags,
|
invalidation_flags: &mut ComputedValueFlags,
|
||||||
) -> KleeneValue
|
) -> KleeneValue
|
||||||
where
|
where
|
||||||
|
|
|
@ -967,7 +967,7 @@ impl Stylist {
|
||||||
element: E,
|
element: E,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
rule_inclusion: RuleInclusion,
|
rule_inclusion: RuleInclusion,
|
||||||
originating_element_style: &Arc<ComputedValues>,
|
originating_element_style: &ComputedValues,
|
||||||
parent_style: &Arc<ComputedValues>,
|
parent_style: &Arc<ComputedValues>,
|
||||||
is_probe: bool,
|
is_probe: bool,
|
||||||
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
|
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
|
||||||
|
@ -1113,7 +1113,7 @@ impl Stylist {
|
||||||
&self,
|
&self,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
element: E,
|
element: E,
|
||||||
originating_element_style: &Arc<ComputedValues>,
|
originating_element_style: &ComputedValues,
|
||||||
parent_style: &Arc<ComputedValues>,
|
parent_style: &Arc<ComputedValues>,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
is_probe: bool,
|
is_probe: bool,
|
||||||
|
@ -1144,7 +1144,7 @@ impl Stylist {
|
||||||
|
|
||||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||||
matching_context.extra_data.originating_element_style =
|
matching_context.extra_data.originating_element_style =
|
||||||
Some(originating_element_style.clone());
|
Some(originating_element_style);
|
||||||
|
|
||||||
self.push_applicable_declarations(
|
self.push_applicable_declarations(
|
||||||
element,
|
element,
|
||||||
|
@ -1176,7 +1176,7 @@ impl Stylist {
|
||||||
);
|
);
|
||||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||||
matching_context.extra_data.originating_element_style =
|
matching_context.extra_data.originating_element_style =
|
||||||
Some(originating_element_style.clone());
|
Some(originating_element_style);
|
||||||
|
|
||||||
self.push_applicable_declarations(
|
self.push_applicable_declarations(
|
||||||
element,
|
element,
|
||||||
|
@ -2398,7 +2398,7 @@ impl CascadeData {
|
||||||
.matches(
|
.matches(
|
||||||
stylist.device(),
|
stylist.device(),
|
||||||
element,
|
element,
|
||||||
context.extra_data.originating_element_style.as_ref(),
|
context.extra_data.originating_element_style,
|
||||||
&mut context.extra_data.cascade_input_flags,
|
&mut context.extra_data.cascade_input_flags,
|
||||||
)
|
)
|
||||||
.to_bool(/* unknown = */ false);
|
.to_bool(/* unknown = */ false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue