Bug 1471063: Simplify selector serialization. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 26 Jun 2018 00:33:39 +0200
changeset 810470 1c3a32e888217f4025d75a01275443040bed9219
parent 810469 94cf634b575b75a7dd9c4ff8556c9abdd963342b
push id114007
push userbmo:emilio@crisal.io
push dateMon, 25 Jun 2018 22:53:31 +0000
reviewersxidorn
bugs1471063
milestone62.0a1
Bug 1471063: Simplify selector serialization. r?xidorn MozReview-Commit-ID: 959U7yd5W9j
servo/components/selectors/parser.rs
--- a/servo/components/selectors/parser.rs
+++ b/servo/components/selectors/parser.rs
@@ -990,18 +990,17 @@ impl<Impl: SelectorImpl> ToCss for Selec
         // dominates anyway.
         //
         // NB: A parse-order iterator is a Rev<>, which doesn't expose as_slice(),
         // which we need for |split|. So we split by combinators on a match-order
         // sequence and then reverse.
 
         let mut combinators = self.iter_raw_match_order()
             .rev()
-            .filter(|x| x.is_combinator())
-            .peekable();
+            .filter_map(|x| x.as_combinator());
         let compound_selectors = self.iter_raw_match_order()
             .as_slice()
             .split(|x| x.is_combinator())
             .rev();
 
         let mut combinators_exhausted = false;
         for compound in compound_selectors {
             debug_assert!(!combinators_exhausted);
@@ -1024,37 +1023,38 @@ impl<Impl: SelectorImpl> ToCss for Selec
             let (can_elide_namespace, first_non_namespace) = match compound[0] {
                 Component::ExplicitAnyNamespace |
                 Component::ExplicitNoNamespace |
                 Component::Namespace(..) => (false, 1),
                 Component::DefaultNamespace(..) => (true, 1),
                 _ => (true, 0),
             };
             let mut perform_step_2 = true;
+            let next_combinator = combinators.next();
             if first_non_namespace == compound.len() - 1 {
-                match (combinators.peek(), &compound[first_non_namespace]) {
+                match (next_combinator, &compound[first_non_namespace]) {
                     // We have to be careful here, because if there is a
                     // pseudo element "combinator" there isn't really just
                     // the one simple selector. Technically this compound
                     // selector contains the pseudo element selector as well
                     // -- Combinator::PseudoElement, just like
                     // Combinator::SlotAssignment, don't exist in the
                     // spec.
-                    (Some(&&Component::Combinator(Combinator::PseudoElement)), _) |
-                    (Some(&&Component::Combinator(Combinator::SlotAssignment)), _) => (),
+                    (Some(Combinator::PseudoElement), _) |
+                    (Some(Combinator::SlotAssignment), _) => (),
                     (_, &Component::ExplicitUniversalType) => {
                         // Iterate over everything so we serialize the namespace
                         // too.
                         for simple in compound.iter() {
                             simple.to_css(dest)?;
                         }
                         // Skip step 2, which is an "otherwise".
                         perform_step_2 = false;
                     },
-                    (_, _) => (),
+                    _ => (),
                 }
             }
 
             // 2. Otherwise, for each simple selector in the compound selectors
             //    that is not a universal selector of which the namespace prefix
             //    maps to a namespace that is not the default namespace
             //    serialize the simple selector and append the result to s.
             //
@@ -1077,17 +1077,17 @@ impl<Impl: SelectorImpl> ToCss for Selec
                 }
             }
 
             // 3. If this is not the last part of the chain of the selector
             //    append a single SPACE (U+0020), followed by the combinator
             //    ">", "+", "~", ">>", "||", as appropriate, followed by another
             //    single SPACE (U+0020) if the combinator was not whitespace, to
             //    s.
-            match combinators.next() {
+            match next_combinator {
                 Some(c) => c.to_css(dest)?,
                 None => combinators_exhausted = true,
             };
 
             // 4. If this is the last part of the chain of the selector and
             //    there is a pseudo-element, append "::" followed by the name of
             //    the pseudo-element, to s.
             //