From 07456bbd3d6eb770c5464b35c33d3f2a239ca276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 26 Jun 2018 00:33:39 +0200 Subject: [PATCH] style: Simplify selector serialization. Bug: 1471063 Reviewed-by: xidorn MozReview-Commit-ID: 959U7yd5W9j --- components/selectors/parser.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index ac539045115..399f21e6361 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -995,8 +995,7 @@ impl ToCss for Selector { 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()) @@ -1029,8 +1028,9 @@ impl ToCss for Selector { _ => (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 @@ -1038,8 +1038,8 @@ impl ToCss for Selector { // -- 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. @@ -1049,7 +1049,7 @@ impl ToCss for Selector { // Skip step 2, which is an "otherwise". perform_step_2 = false; }, - (_, _) => (), + _ => (), } } @@ -1082,7 +1082,7 @@ impl ToCss for Selector { // ">", "+", "~", ">>", "||", 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, };