Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.

Make the static arrays of style-affecting attributes thread-local. #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down