mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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>,
|
||||
|
||||
/// Extra implementation-dependent matching data.
|
||||
pub extra_data: Impl::ExtraMatchingData,
|
||||
pub extra_data: Impl::ExtraMatchingData<'a>,
|
||||
|
||||
quirks_mode: QuirksMode,
|
||||
needs_selector_flags: NeedsSelectorFlags,
|
||||
|
|
|
@ -202,7 +202,7 @@ macro_rules! with_all_bounds {
|
|||
/// are parameterized on SelectorImpl. See
|
||||
/// <https://github.com/rust-lang/rust/issues/26925>
|
||||
pub trait SelectorImpl: Clone + Debug + Sized + 'static {
|
||||
type ExtraMatchingData: Sized + Default + 'static;
|
||||
type ExtraMatchingData<'a>: Sized + Default;
|
||||
type AttrValue: $($InSelector)*;
|
||||
type Identifier: $($InSelector)*;
|
||||
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName>;
|
||||
|
@ -2638,7 +2638,7 @@ pub mod tests {
|
|||
}
|
||||
|
||||
impl SelectorImpl for DummySelectorImpl {
|
||||
type ExtraMatchingData = ();
|
||||
type ExtraMatchingData<'a> = std::marker::PhantomData<&'a ()>;
|
||||
type AttrValue = DummyAttrValue;
|
||||
type Identifier = DummyAtom;
|
||||
type LocalName = DummyAtom;
|
||||
|
|
|
@ -18,7 +18,6 @@ use cssparser::{CowRcStr, SourceLocation, ToCss, Token};
|
|||
use dom::{DocumentState, ElementState};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use selectors::SelectorList;
|
||||
use servo_arc::Arc;
|
||||
use std::fmt;
|
||||
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
|
||||
/// selector-matching or invalidation.
|
||||
#[derive(Default)]
|
||||
pub struct ExtraMatchingData {
|
||||
pub struct ExtraMatchingData<'a> {
|
||||
/// The invalidation data to invalidate doc-state pseudo-classes correctly.
|
||||
pub invalidation_data: InvalidationMatchingData,
|
||||
|
||||
|
@ -246,11 +245,11 @@ pub struct ExtraMatchingData {
|
|||
|
||||
/// The style of the originating element in order to evaluate @container
|
||||
/// size queries affecting pseudo-elements.
|
||||
pub originating_element_style: Option<Arc<ComputedValues>>,
|
||||
pub originating_element_style: Option<&'a ComputedValues>,
|
||||
}
|
||||
|
||||
impl ::selectors::SelectorImpl for SelectorImpl {
|
||||
type ExtraMatchingData = ExtraMatchingData;
|
||||
type ExtraMatchingData<'a> = ExtraMatchingData<'a>;
|
||||
type AttrValue = AtomString;
|
||||
type Identifier = AtomIdent;
|
||||
type LocalName = AtomIdent;
|
||||
|
|
|
@ -103,6 +103,15 @@ impl ComputedValues {
|
|||
).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]
|
||||
pub fn is_pseudo_style(&self) -> bool {
|
||||
self.0.mPseudoType != PseudoStyleType::NotPseudo
|
||||
|
@ -208,8 +217,8 @@ impl ComputedValuesInner {
|
|||
&self,
|
||||
pseudo_ty,
|
||||
);
|
||||
// We're simulating move semantics by having C++ do a memcpy and then forgetting
|
||||
// it on this end.
|
||||
// We're simulating move semantics by having C++ do a memcpy and
|
||||
// then forgetting it on this end.
|
||||
forget(self);
|
||||
UniqueArc::assume_init(arc).shareable()
|
||||
}
|
||||
|
|
|
@ -507,7 +507,7 @@ where
|
|||
|
||||
fn match_pseudo(
|
||||
&mut self,
|
||||
originating_element_style: &Arc<ComputedValues>,
|
||||
originating_element_style: &ComputedValues,
|
||||
pseudo_element: &PseudoElement,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
) -> Option<MatchingResults> {
|
||||
|
@ -544,7 +544,7 @@ where
|
|||
NeedsSelectorFlags::Yes,
|
||||
);
|
||||
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
|
||||
// traversing them.
|
||||
|
|
|
@ -135,14 +135,14 @@ enum TraversalResult<T> {
|
|||
Done(T),
|
||||
}
|
||||
|
||||
fn traverse_container<E, S, F, R>(
|
||||
fn traverse_container<E, F, R>(
|
||||
mut e: E,
|
||||
originating_element_style: Option<&S>,
|
||||
originating_element_style: Option<&ComputedValues>,
|
||||
evaluator: F,
|
||||
) -> Option<(E, R)>
|
||||
where
|
||||
E: TElement,
|
||||
F: Fn(E, Option<&S>) -> TraversalResult<R>,
|
||||
F: Fn(E, Option<&ComputedValues>) -> TraversalResult<R>,
|
||||
{
|
||||
if originating_element_style.is_some() {
|
||||
match evaluator(e, originating_element_style) {
|
||||
|
@ -185,7 +185,7 @@ impl ContainerCondition {
|
|||
fn valid_container_info<E>(
|
||||
&self,
|
||||
potential_container: E,
|
||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
||||
originating_element_style: Option<&ComputedValues>,
|
||||
) -> TraversalResult<ContainerLookupResult<E>>
|
||||
where
|
||||
E: TElement,
|
||||
|
@ -198,7 +198,7 @@ impl ContainerCondition {
|
|||
Some(d) => d,
|
||||
None => return TraversalResult::InProgress,
|
||||
};
|
||||
data.styles.primary()
|
||||
&**data.styles.primary()
|
||||
},
|
||||
};
|
||||
let wm = style.writing_mode;
|
||||
|
@ -220,7 +220,7 @@ impl ContainerCondition {
|
|||
}
|
||||
|
||||
let size = potential_container.query_container_size(&box_style.clone_display());
|
||||
let style = style.clone();
|
||||
let style = style.to_arc();
|
||||
TraversalResult::Done(ContainerLookupResult {
|
||||
element: potential_container,
|
||||
info: ContainerInfo { size, wm },
|
||||
|
@ -232,7 +232,7 @@ impl ContainerCondition {
|
|||
pub fn find_container<E>(
|
||||
&self,
|
||||
e: E,
|
||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
||||
originating_element_style: Option<&ComputedValues>,
|
||||
) -> Option<ContainerLookupResult<E>>
|
||||
where
|
||||
E: TElement,
|
||||
|
@ -254,7 +254,7 @@ impl ContainerCondition {
|
|||
&self,
|
||||
device: &Device,
|
||||
element: E,
|
||||
originating_element_style: Option<&Arc<ComputedValues>>,
|
||||
originating_element_style: Option<&ComputedValues>,
|
||||
invalidation_flags: &mut ComputedValueFlags,
|
||||
) -> KleeneValue
|
||||
where
|
||||
|
|
|
@ -967,7 +967,7 @@ impl Stylist {
|
|||
element: E,
|
||||
pseudo: &PseudoElement,
|
||||
rule_inclusion: RuleInclusion,
|
||||
originating_element_style: &Arc<ComputedValues>,
|
||||
originating_element_style: &ComputedValues,
|
||||
parent_style: &Arc<ComputedValues>,
|
||||
is_probe: bool,
|
||||
matching_fn: Option<&dyn Fn(&PseudoElement) -> bool>,
|
||||
|
@ -1113,7 +1113,7 @@ impl Stylist {
|
|||
&self,
|
||||
guards: &StylesheetGuards,
|
||||
element: E,
|
||||
originating_element_style: &Arc<ComputedValues>,
|
||||
originating_element_style: &ComputedValues,
|
||||
parent_style: &Arc<ComputedValues>,
|
||||
pseudo: &PseudoElement,
|
||||
is_probe: bool,
|
||||
|
@ -1144,7 +1144,7 @@ impl Stylist {
|
|||
|
||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||
matching_context.extra_data.originating_element_style =
|
||||
Some(originating_element_style.clone());
|
||||
Some(originating_element_style);
|
||||
|
||||
self.push_applicable_declarations(
|
||||
element,
|
||||
|
@ -1176,7 +1176,7 @@ impl Stylist {
|
|||
);
|
||||
matching_context.pseudo_element_matching_fn = matching_fn;
|
||||
matching_context.extra_data.originating_element_style =
|
||||
Some(originating_element_style.clone());
|
||||
Some(originating_element_style);
|
||||
|
||||
self.push_applicable_declarations(
|
||||
element,
|
||||
|
@ -2398,7 +2398,7 @@ impl CascadeData {
|
|||
.matches(
|
||||
stylist.device(),
|
||||
element,
|
||||
context.extra_data.originating_element_style.as_ref(),
|
||||
context.extra_data.originating_element_style,
|
||||
&mut context.extra_data.cascade_input_flags,
|
||||
)
|
||||
.to_bool(/* unknown = */ false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue