mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
cached element class names in style sharing cache with lazy computation
This commit is contained in:
parent
8a75810eba
commit
b076d7e28c
1 changed files with 15 additions and 7 deletions
|
@ -189,6 +189,8 @@ struct StyleSharingCandidate {
|
||||||
style: Arc<ComputedValues>,
|
style: Arc<ComputedValues>,
|
||||||
/// The cached common style affecting attribute info.
|
/// The cached common style affecting attribute info.
|
||||||
common_style_affecting_attributes: Option<CommonStyleAffectingAttributes>,
|
common_style_affecting_attributes: Option<CommonStyleAffectingAttributes>,
|
||||||
|
/// the cached class names.
|
||||||
|
class_attributes: Option<Vec<Atom>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<StyleSharingCandidate> for StyleSharingCandidate {
|
impl PartialEq<StyleSharingCandidate> for StyleSharingCandidate {
|
||||||
|
@ -268,7 +270,7 @@ fn element_matches_candidate<E: TElement>(element: &E,
|
||||||
miss!(StyleAttr)
|
miss!(StyleAttr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !have_same_class(element, candidate_element) {
|
if !have_same_class(element, candidate, candidate_element) {
|
||||||
miss!(Class)
|
miss!(Class)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,15 +378,20 @@ pub fn rare_style_affecting_attributes() -> [Atom; 3] {
|
||||||
[ atom!("bgcolor"), atom!("border"), atom!("colspan") ]
|
[ 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.
|
// XXX Efficiency here, I'm only validating ideas.
|
||||||
let mut first = vec![];
|
let mut element_class_attributes = vec![];
|
||||||
let mut second = vec![];
|
element.each_class(|c| element_class_attributes.push(c.clone()));
|
||||||
|
|
||||||
element.each_class(|c| first.push(c.clone()));
|
if candidate.class_attributes.is_none() {
|
||||||
candidate.each_class(|c| second.push(c.clone()));
|
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.
|
// TODO: These re-match the candidate every time, which is suboptimal.
|
||||||
|
@ -457,6 +464,7 @@ impl StyleSharingCandidateCache {
|
||||||
node: node.to_unsafe(),
|
node: node.to_unsafe(),
|
||||||
style: style.clone(),
|
style: style.clone(),
|
||||||
common_style_affecting_attributes: None,
|
common_style_affecting_attributes: None,
|
||||||
|
class_attributes: None,
|
||||||
}, ());
|
}, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue