Bug 1364412: Store full selectors in the Rule object. r?bholley draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 12 May 2017 17:02:07 +0200
changeset 577934 77b07afe50e3e283d80ff825c93be5945fb4af5e
parent 577933 e6feacac29cd04f60435f0caaf0079f6e89c0194
child 577935 26d43d01ab2233259c115de0ff866b14945cfcfa
push id58837
push userbmo:emilio+bugs@crisal.io
push dateMon, 15 May 2017 17:46:39 +0000
reviewersbholley
bugs1364412
milestone55.0a1
Bug 1364412: Store full selectors in the Rule object. r?bholley MozReview-Commit-ID: EKLKxNCghLD
servo/components/style/stylist.rs
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -453,20 +453,19 @@ impl Stylist {
             self.pseudos_map
                 .entry(pseudo_selector.pseudo_element().clone())
                 .or_insert_with(PerPseudoElementSelectorMap::new)
                 .borrow_for_origin(&stylesheet.origin)
         } else {
             self.element_map.borrow_for_origin(&stylesheet.origin)
         };
 
-        map.insert(Rule::new(selector.inner.clone(),
+        map.insert(Rule::new(selector.clone(),
                              rule.clone(),
-                             self.rules_source_order,
-                             selector.specificity));
+                             self.rules_source_order));
     }
 
     #[inline]
     fn note_for_revalidation(&mut self, selector: &Selector<SelectorImpl>) {
         if needs_revalidation(selector) {
             self.selectors_for_cache_revalidation.insert(selector.inner.clone());
         }
     }
@@ -1316,17 +1315,17 @@ impl SelectorMap<Rule> {
                                -> Vec<ApplicableDeclarationBlock> {
         debug_assert!(!cascade_level.is_important());
         if self.is_empty() {
             return vec![];
         }
 
         let mut rules_list = vec![];
         for rule in self.other.iter() {
-            if rule.selector.complex.iter_raw().next().is_none() {
+            if rule.selector.inner.complex.iter_raw().next().is_none() {
                 rules_list.push(rule.to_applicable_declaration_block(cascade_level));
             }
         }
 
         sort_by_key(&mut rules_list,
                     |block| (block.specificity, block.source_order));
 
         rules_list
@@ -1366,18 +1365,21 @@ impl SelectorMap<Rule> {
                                    relations: &mut StyleRelations,
                                    flags_setter: &mut F,
                                    cascade_level: CascadeLevel)
         where E: Element<Impl=SelectorImpl>,
               V: VecLike<ApplicableDeclarationBlock>,
               F: FnMut(&E, ElementSelectorFlags),
     {
         for rule in rules.iter() {
-            if matches_selector(&rule.selector, element, parent_bf,
-                                relations, flags_setter) {
+            if matches_selector(&rule.selector.inner,
+                                element,
+                                parent_bf,
+                                relations,
+                                flags_setter) {
                 matching_rules.push(
                     rule.to_applicable_declaration_block(cascade_level));
             }
         }
     }
 }
 
 impl<T> SelectorMap<T> where T: Clone + Borrow<SelectorInner<SelectorImpl>> {
@@ -1574,62 +1576,55 @@ pub fn get_local_name(selector: &Selecto
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
 #[derive(Clone, Debug)]
 pub struct Rule {
     /// The selector this struct represents. We store this and the
     /// any_{important,normal} booleans inline in the Rule to avoid
     /// pointer-chasing when gathering applicable declarations, which
     /// can ruin performance when there are a lot of rules.
     #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
-    pub selector: SelectorInner<SelectorImpl>,
+    pub selector: Selector<SelectorImpl>,
     /// The actual style rule.
     #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
     pub style_rule: Arc<Locked<StyleRule>>,
     /// The source order this style rule appears in.
     pub source_order: usize,
-    /// The specificity of the rule this selector represents.
-    ///
-    /// Note: The top two bits of this are unused, and could be used to store
-    /// flags.
-    specificity: u32,
 }
 
 impl Borrow<SelectorInner<SelectorImpl>> for Rule {
     fn borrow(&self) -> &SelectorInner<SelectorImpl> {
-        &self.selector
+        &self.selector.inner
     }
 }
 
 impl Rule {
     /// Returns the specificity of the rule.
     pub fn specificity(&self) -> u32 {
-        self.specificity
+        self.selector.specificity
     }
 
     fn to_applicable_declaration_block(&self, level: CascadeLevel) -> ApplicableDeclarationBlock {
         ApplicableDeclarationBlock {
             source: StyleSource::Style(self.style_rule.clone()),
             level: level,
             source_order: self.source_order,
             specificity: self.specificity(),
         }
     }
 
     /// Creates a new Rule.
-    pub fn new(selector: SelectorInner<SelectorImpl>,
+    pub fn new(selector: Selector<SelectorImpl>,
                style_rule: Arc<Locked<StyleRule>>,
-               source_order: usize,
-               specificity: u32)
+               source_order: usize)
                -> Self
     {
         Rule {
             selector: selector,
             style_rule: style_rule,
             source_order: source_order,
-            specificity: specificity,
         }
     }
 }
 
 /// A property declaration together with its precedence among rules of equal
 /// specificity so that we can sort them.
 ///
 /// This represents the declarations in a given declaration block for a given