From 7a431946c199efadb9b0a0a998fd90c0bbf7c647 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 11 Jun 2015 15:10:49 -0700 Subject: [PATCH] Make the static arrays of style-affecting attributes thread-local instead of regenerating and dropping them on the stack over and over. Reduces I-cache footprint and memory barrier traffic on ARM. --- src/matching.rs | 74 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/matching.rs b/src/matching.rs index c5c5f05..b863884 100644 --- a/src/matching.rs +++ b/src/matching.rs @@ -533,37 +533,35 @@ pub enum CommonStyleAffectingAttributeMode { // NB: This must match the order in `layout::css::matching::CommonStyleAffectingAttributes`. #[inline] -pub fn common_style_affecting_attributes() -> [CommonStyleAffectingAttributeInfo; 5] { - [ - CommonStyleAffectingAttributeInfo { - atom: atom!("hidden"), - mode: CommonStyleAffectingAttributeMode::IsPresent(HIDDEN_ATTRIBUTE), - }, - CommonStyleAffectingAttributeInfo { - atom: atom!("nowrap"), - mode: CommonStyleAffectingAttributeMode::IsPresent(NO_WRAP_ATTRIBUTE), - }, - CommonStyleAffectingAttributeInfo { - atom: atom!("align"), - mode: CommonStyleAffectingAttributeMode::IsEqual("left", ALIGN_LEFT_ATTRIBUTE), - }, - CommonStyleAffectingAttributeInfo { - atom: atom!("align"), - mode: CommonStyleAffectingAttributeMode::IsEqual("center", ALIGN_CENTER_ATTRIBUTE), - }, - CommonStyleAffectingAttributeInfo { - atom: atom!("align"), - mode: CommonStyleAffectingAttributeMode::IsEqual("right", ALIGN_RIGHT_ATTRIBUTE), - } - ] -} +thread_local!(pub static COMMON_STYLE_AFFECTING_ATTRIBUTES: [CommonStyleAffectingAttributeInfo; 5] = [ + CommonStyleAffectingAttributeInfo { + atom: atom!("hidden"), + mode: CommonStyleAffectingAttributeMode::IsPresent(HIDDEN_ATTRIBUTE), + }, + CommonStyleAffectingAttributeInfo { + atom: atom!("nowrap"), + mode: CommonStyleAffectingAttributeMode::IsPresent(NO_WRAP_ATTRIBUTE), + }, + CommonStyleAffectingAttributeInfo { + atom: atom!("align"), + mode: CommonStyleAffectingAttributeMode::IsEqual("left", ALIGN_LEFT_ATTRIBUTE), + }, + CommonStyleAffectingAttributeInfo { + atom: atom!("align"), + mode: CommonStyleAffectingAttributeMode::IsEqual("center", ALIGN_CENTER_ATTRIBUTE), + }, + CommonStyleAffectingAttributeInfo { + atom: atom!("align"), + mode: CommonStyleAffectingAttributeMode::IsEqual("right", ALIGN_RIGHT_ATTRIBUTE), + } +]); /// Attributes that, if present, disable style sharing. All legacy HTML attributes must be in /// either this list or `common_style_affecting_attributes`. See the comment in /// `synthesize_presentational_hints_for_legacy_attributes`. -pub fn rare_style_affecting_attributes() -> [Atom; 3] { - [ atom!("bgcolor"), atom!("border"), atom!("colspan") ] -} +thread_local!(pub static RARE_STYLE_AFFECTING_ATTRIBUTES: [Atom; 3] = [ + atom!("bgcolor"), atom!("border"), atom!("colspan") +]); /// Determines whether the given element matches the given single selector. /// @@ -604,10 +602,12 @@ pub fn matches_simple_selector<'a,N>(selector: &SimpleSelector, SimpleSelector::AttrExists(ref attr) => { // NB(pcwalton): If you update this, remember to update the corresponding list in // `can_share_style_with()` as well. - if common_style_affecting_attributes().iter().all(|common_attr_info| { - !(common_attr_info.atom == attr.name && match common_attr_info.mode { - CommonStyleAffectingAttributeMode::IsPresent(_) => true, - CommonStyleAffectingAttributeMode::IsEqual(..) => false, + if COMMON_STYLE_AFFECTING_ATTRIBUTES.with(|common_style_affecting_attributes| { + common_style_affecting_attributes.iter().all(|common_attr_info| { + !(common_attr_info.atom == attr.name && match common_attr_info.mode { + CommonStyleAffectingAttributeMode::IsPresent(_) => true, + CommonStyleAffectingAttributeMode::IsEqual(..) => false, + }) }) }) { *shareable = false; @@ -616,10 +616,14 @@ pub fn matches_simple_selector<'a,N>(selector: &SimpleSelector, } SimpleSelector::AttrEqual(ref attr, ref value, case_sensitivity) => { if *value != "DIR" && - common_style_affecting_attributes().iter().all(|common_attr_info| { - !(common_attr_info.atom == attr.name && match common_attr_info.mode { - CommonStyleAffectingAttributeMode::IsEqual(target_value, _) => *value == target_value, - CommonStyleAffectingAttributeMode::IsPresent(_) => false, + COMMON_STYLE_AFFECTING_ATTRIBUTES.with(|common_style_affecting_attributes| { + common_style_affecting_attributes.iter().all(|common_attr_info| { + !(common_attr_info.atom == attr.name && match common_attr_info.mode { + CommonStyleAffectingAttributeMode::IsEqual(target_value, _) => { + *value == target_value + } + CommonStyleAffectingAttributeMode::IsPresent(_) => false, + }) }) }) { // FIXME(pcwalton): Remove once we start actually supporting RTL text. This is in