style: Remove some unneeded indirection.

All TElement's implement Copy, and are just pointers, so the double indirection
is stupid.

I'm going to try to see if removing this double-indirection fixes some
selector-matching performance, and this is a trivial pre-requisite while I wait
for Talos results.
This commit is contained in:
Emilio Cobos Álvarez 2018-01-10 03:46:54 +01:00
parent bfc91c5e12
commit 8f6455b9df
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 37 additions and 40 deletions

View file

@ -398,22 +398,20 @@ pub trait ThreadSafeLayoutElement
&style_pseudo, &style_pseudo,
Some(data.styles.primary()), Some(data.styles.primary()),
CascadeFlags::empty(), CascadeFlags::empty(),
&ServoMetricsProvider) &ServoMetricsProvider,
.clone() )
} }
PseudoElementCascadeType::Lazy => { PseudoElementCascadeType::Lazy => {
context.stylist context.stylist.lazily_compute_pseudo_element_style(
.lazily_compute_pseudo_element_style( &context.guards,
&context.guards, unsafe { self.unsafe_get() },
unsafe { &self.unsafe_get() }, &style_pseudo,
&style_pseudo, RuleInclusion::All,
RuleInclusion::All, data.styles.primary(),
data.styles.primary(), /* is_probe = */ false,
/* is_probe = */ false, &ServoMetricsProvider,
&ServoMetricsProvider, /* matching_func = */ None,
/* matching_func = */ None) ).unwrap()
.unwrap()
.clone()
} }
} }
} }
@ -424,7 +422,7 @@ pub trait ThreadSafeLayoutElement
fn selected_style(&self) -> Arc<ComputedValues> { fn selected_style(&self) -> Arc<ComputedValues> {
let data = self.style_data(); let data = self.style_data();
data.styles.pseudos data.styles.pseudos
.get(&PseudoElement::Selection).map(|s| s) .get(&PseudoElement::Selection)
.unwrap_or(data.styles.primary()) .unwrap_or(data.styles.primary())
.clone() .clone()
} }

View file

@ -155,8 +155,8 @@ impl SelectorMap<Rule> {
/// Sort the Rules at the end to maintain cascading order. /// Sort the Rules at the end to maintain cascading order.
pub fn get_all_matching_rules<E, F>( pub fn get_all_matching_rules<E, F>(
&self, &self,
element: &E, element: E,
rule_hash_target: &E, rule_hash_target: E,
matching_rules_list: &mut ApplicableDeclarationList, matching_rules_list: &mut ApplicableDeclarationList,
context: &mut MatchingContext<E::Impl>, context: &mut MatchingContext<E::Impl>,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
@ -217,7 +217,7 @@ impl SelectorMap<Rule> {
/// Adds rules in `rules` that match `element` to the `matching_rules` list. /// Adds rules in `rules` that match `element` to the `matching_rules` list.
fn get_matching_rules<E, F>( fn get_matching_rules<E, F>(
element: &E, element: E,
rules: &[Rule], rules: &[Rule],
matching_rules: &mut ApplicableDeclarationList, matching_rules: &mut ApplicableDeclarationList,
context: &mut MatchingContext<E::Impl>, context: &mut MatchingContext<E::Impl>,
@ -232,7 +232,7 @@ impl SelectorMap<Rule> {
if matches_selector(&rule.selector, if matches_selector(&rule.selector,
0, 0,
Some(&rule.hashes), Some(&rule.hashes),
element, &element,
context, context,
flags_setter) { flags_setter) {
matching_rules.push( matching_rules.push(

View file

@ -428,7 +428,7 @@ where
// Compute the primary rule node. // Compute the primary rule node.
stylist.push_applicable_declarations( stylist.push_applicable_declarations(
&self.element, self.element,
implemented_pseudo.as_ref(), implemented_pseudo.as_ref(),
self.element.style_attribute(), self.element.style_attribute(),
self.element.get_smil_override(), self.element.get_smil_override(),
@ -502,7 +502,7 @@ where
// NB: We handle animation rules for ::before and ::after when // NB: We handle animation rules for ::before and ::after when
// traversing them. // traversing them.
stylist.push_applicable_declarations( stylist.push_applicable_declarations(
&self.element, self.element,
Some(pseudo_element), Some(pseudo_element),
None, None,
None, None,

View file

@ -795,7 +795,7 @@ impl Stylist {
pub fn lazily_compute_pseudo_element_style<E>( pub fn lazily_compute_pseudo_element_style<E>(
&self, &self,
guards: &StylesheetGuards, guards: &StylesheetGuards,
element: &E, element: E,
pseudo: &PseudoElement, pseudo: &PseudoElement,
rule_inclusion: RuleInclusion, rule_inclusion: RuleInclusion,
parent_style: &ComputedValues, parent_style: &ComputedValues,
@ -982,7 +982,7 @@ impl Stylist {
fn lazy_pseudo_rules<E>( fn lazy_pseudo_rules<E>(
&self, &self,
guards: &StylesheetGuards, guards: &StylesheetGuards,
element: &E, element: E,
parent_style: &ComputedValues, parent_style: &ComputedValues,
pseudo: &PseudoElement, pseudo: &PseudoElement,
is_probe: bool, is_probe: bool,
@ -1203,7 +1203,7 @@ impl Stylist {
/// This corresponds to `ElementRuleCollector` in WebKit. /// This corresponds to `ElementRuleCollector` in WebKit.
pub fn push_applicable_declarations<E, F>( pub fn push_applicable_declarations<E, F>(
&self, &self,
element: &E, element: E,
pseudo_element: Option<&PseudoElement>, pseudo_element: Option<&PseudoElement>,
style_attribute: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>, style_attribute: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>, smil_override: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
@ -1238,7 +1238,7 @@ impl Stylist {
if let Some(map) = self.cascade_data.user_agent.cascade_data.normal_rules(pseudo_element) { if let Some(map) = self.cascade_data.user_agent.cascade_data.normal_rules(pseudo_element) {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
&rule_hash_target, rule_hash_target,
applicable_declarations, applicable_declarations,
context, context,
self.quirks_mode, self.quirks_mode,
@ -1276,7 +1276,7 @@ impl Stylist {
if let Some(map) = self.cascade_data.user.normal_rules(pseudo_element) { if let Some(map) = self.cascade_data.user.normal_rules(pseudo_element) {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
&rule_hash_target, rule_hash_target,
applicable_declarations, applicable_declarations,
context, context,
self.quirks_mode, self.quirks_mode,
@ -1307,7 +1307,7 @@ impl Stylist {
if let Some(map) = stylist.cascade_data.author.slotted_rules(pseudo_element) { if let Some(map) = stylist.cascade_data.author.slotted_rules(pseudo_element) {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
&rule_hash_target, rule_hash_target,
applicable_declarations, applicable_declarations,
context, context,
self.quirks_mode, self.quirks_mode,
@ -1341,7 +1341,7 @@ impl Stylist {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
&rule_hash_target, rule_hash_target,
applicable_declarations, applicable_declarations,
&mut matching_context, &mut matching_context,
stylist.quirks_mode, stylist.quirks_mode,
@ -1358,7 +1358,7 @@ impl Stylist {
if let Some(map) = self.cascade_data.author.normal_rules(pseudo_element) { if let Some(map) = self.cascade_data.author.normal_rules(pseudo_element) {
map.get_all_matching_rules( map.get_all_matching_rules(
element, element,
&rule_hash_target, rule_hash_target,
applicable_declarations, applicable_declarations,
context, context,
self.quirks_mode, self.quirks_mode,

View file

@ -2260,17 +2260,16 @@ fn get_pseudo_style(
}; };
let guards = StylesheetGuards::same(guard); let guards = StylesheetGuards::same(guard);
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
doc_data.stylist doc_data.stylist.lazily_compute_pseudo_element_style(
.lazily_compute_pseudo_element_style( &guards,
&guards, element,
&element, &pseudo,
&pseudo, rule_inclusion,
rule_inclusion, base,
base, is_probe,
is_probe, &metrics,
&metrics, matching_func,
matching_func, )
)
}, },
}; };