Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached element class names in style sharing cache with lazy computation #12962

Merged
merged 1 commit into from Aug 22, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -189,6 +189,8 @@ struct StyleSharingCandidate {
style: Arc<ComputedValues>,
/// The cached common style affecting attribute info.
common_style_affecting_attributes: Option<CommonStyleAffectingAttributes>,
/// the cached class names.
class_attributes: Option<Vec<Atom>>,
}

impl PartialEq<StyleSharingCandidate> for StyleSharingCandidate {
@@ -268,7 +270,7 @@ fn element_matches_candidate<E: TElement>(element: &E,
miss!(StyleAttr)
}

if !have_same_class(element, candidate_element) {
if !have_same_class(element, candidate, candidate_element) {
miss!(Class)
}

@@ -376,15 +378,20 @@ pub fn rare_style_affecting_attributes() -> [Atom; 3] {
[ atom!("bgcolor"), atom!("border"), atom!("colspan") ]
}

fn have_same_class<E: TElement>(element: &E, candidate: &E) -> bool {
fn have_same_class<E: TElement>(element: &E,
candidate: &mut StyleSharingCandidate,
candidate_element: &E) -> bool {
// XXX Efficiency here, I'm only validating ideas.
let mut first = vec![];
let mut second = vec![];
let mut element_class_attributes = vec![];
element.each_class(|c| element_class_attributes.push(c.clone()));

element.each_class(|c| first.push(c.clone()));
candidate.each_class(|c| second.push(c.clone()));
if candidate.class_attributes.is_none() {
let mut attrs = vec![];
candidate_element.each_class(|c| attrs.push(c.clone()));
candidate.class_attributes = Some(attrs)
}

first == second
element_class_attributes == candidate.class_attributes.clone().unwrap()
}

// TODO: These re-match the candidate every time, which is suboptimal.
@@ -457,6 +464,7 @@ impl StyleSharingCandidateCache {
node: node.to_unsafe(),
style: style.clone(),
common_style_affecting_attributes: None,
class_attributes: None,
}, ());
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.