diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index 7eaf0322d6b..2cdd0913ae6 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -90,8 +90,15 @@ impl ValidationData { where E: TElement, { if self.class_list.is_none() { - let mut class_list = SmallVec::new(); + let mut class_list = SmallVec::<[Atom; 5]>::new(); element.each_class(|c| class_list.push(c.clone())); + // Assuming there are a reasonable number of classes (we use the + // inline capacity as "reasonable number"), sort them to so that + // we don't mistakenly reject sharing candidates when one element + // has "foo bar" and the other has "bar foo". + if !class_list.spilled() { + class_list.sort_by(|a, b| a.get_hash().cmp(&b.get_hash())); + } self.class_list = Some(class_list); } &*self.class_list.as_ref().unwrap() diff --git a/components/style/stylist.rs b/components/style/stylist.rs index def4de9eab1..48f369bd35b 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -966,7 +966,9 @@ impl Stylist { assert_eq!(declaration.level, CascadeLevel::PresHints); } } - // Never share style for elements with preshints + // Note the existence of presentational attributes so that the + // style sharing cache can avoid re-querying them if they don't + // exist. context.relations |= AFFECTED_BY_PRESENTATIONAL_HINTS; } debug!("preshints: {:?}", context.relations);