mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Use each_class rather than get_attr when comparing class lists during style sharing.
This commit is contained in:
parent
7f2a0a1547
commit
a0c425fbef
1 changed files with 17 additions and 12 deletions
|
@ -189,8 +189,7 @@ pub struct StyleSharingCandidate<C: ComputedValues> {
|
||||||
pub style: Arc<C>,
|
pub style: Arc<C>,
|
||||||
pub parent_style: Arc<C>,
|
pub parent_style: Arc<C>,
|
||||||
pub local_name: Atom,
|
pub local_name: Atom,
|
||||||
// FIXME(pcwalton): Should be a list of atoms instead.
|
pub classes: Vec<Atom>,
|
||||||
pub class: Option<String>,
|
|
||||||
pub namespace: Namespace,
|
pub namespace: Namespace,
|
||||||
pub common_style_affecting_attributes: CommonStyleAffectingAttributes,
|
pub common_style_affecting_attributes: CommonStyleAffectingAttributes,
|
||||||
pub link: bool,
|
pub link: bool,
|
||||||
|
@ -201,7 +200,7 @@ impl<C: ComputedValues> PartialEq for StyleSharingCandidate<C> {
|
||||||
arc_ptr_eq(&self.style, &other.style) &&
|
arc_ptr_eq(&self.style, &other.style) &&
|
||||||
arc_ptr_eq(&self.parent_style, &other.parent_style) &&
|
arc_ptr_eq(&self.parent_style, &other.parent_style) &&
|
||||||
self.local_name == other.local_name &&
|
self.local_name == other.local_name &&
|
||||||
self.class == other.class &&
|
self.classes == other.classes &&
|
||||||
self.link == other.link &&
|
self.link == other.link &&
|
||||||
self.namespace == other.namespace &&
|
self.namespace == other.namespace &&
|
||||||
self.common_style_affecting_attributes == other.common_style_affecting_attributes
|
self.common_style_affecting_attributes == other.common_style_affecting_attributes
|
||||||
|
@ -246,12 +245,13 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut classes = Vec::new();
|
||||||
|
element.each_class(|c| classes.push(c.clone()));
|
||||||
Some(StyleSharingCandidate {
|
Some(StyleSharingCandidate {
|
||||||
style: style,
|
style: style,
|
||||||
parent_style: parent_style,
|
parent_style: parent_style,
|
||||||
local_name: element.get_local_name().clone(),
|
local_name: element.get_local_name().clone(),
|
||||||
class: element.get_attr(&ns!(), &atom!("class"))
|
classes: classes,
|
||||||
.map(|string| string.to_owned()),
|
|
||||||
link: element.is_link(),
|
link: element.is_link(),
|
||||||
namespace: (*element.get_namespace()).clone(),
|
namespace: (*element.get_namespace()).clone(),
|
||||||
common_style_affecting_attributes:
|
common_style_affecting_attributes:
|
||||||
|
@ -264,14 +264,19 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(pcwalton): Use `each_class` here instead of slow string comparison.
|
let mut num_classes = 0;
|
||||||
match (&self.class, element.get_attr(&ns!(), &atom!("class"))) {
|
let mut classes_match = true;
|
||||||
(&None, Some(_)) | (&Some(_), None) => return false,
|
element.each_class(|c| {
|
||||||
(&Some(ref this_class), Some(element_class)) if
|
num_classes += 1;
|
||||||
element_class != &**this_class => {
|
// Note that we could do this check more cheaply if we decided to
|
||||||
return false
|
// only consider class lists as equal if the orders match, since
|
||||||
|
// we could then index by num_classes instead of using .contains().
|
||||||
|
if classes_match && !self.classes.contains(c) {
|
||||||
|
classes_match = false;
|
||||||
}
|
}
|
||||||
(&Some(_), Some(_)) | (&None, None) => {}
|
});
|
||||||
|
if !classes_match || num_classes != self.classes.len() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if *element.get_namespace() != self.namespace {
|
if *element.get_namespace() != self.namespace {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue