From b076d7e28c3f4f855cd796bcbb61863736f39b20 Mon Sep 17 00:00:00 2001 From: Ashwin R Date: Sun, 21 Aug 2016 15:20:36 +0530 Subject: [PATCH] cached element class names in style sharing cache with lazy computation --- components/style/matching.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/components/style/matching.rs b/components/style/matching.rs index cb1f70602ad..0dc919853b3 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -189,6 +189,8 @@ struct StyleSharingCandidate { style: Arc, /// The cached common style affecting attribute info. common_style_affecting_attributes: Option, + /// the cached class names. + class_attributes: Option>, } impl PartialEq for StyleSharingCandidate { @@ -268,7 +270,7 @@ fn element_matches_candidate(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(element: &E, candidate: &E) -> bool { +fn have_same_class(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, }, ()); }