diff --git a/src/css.rs b/src/css.rs index 8732367..e00b2da 100644 --- a/src/css.rs +++ b/src/css.rs @@ -100,7 +100,7 @@ impl Css { self.idx = self.blocks.len() + 1; self.inner_rulesets = 0; self.blocks - .push(Toplevel::new_rule(super_selector.zip(selector))); + .push(Toplevel::new_rule(super_selector.zip(&selector))); for rule in rules { self.at_root = true; self.parse_stmt(rule); @@ -111,7 +111,7 @@ impl Css { self.idx += 1; self.at_root = false; self.blocks - .push(Toplevel::new_rule(super_selector.zip(selector))); + .push(Toplevel::new_rule(super_selector.zip(&selector))); for rule in rules { self.parse_stmt(rule); } diff --git a/src/format.rs b/src/format.rs index 568f3eb..c3c7d07 100644 --- a/src/format.rs +++ b/src/format.rs @@ -58,12 +58,7 @@ impl PrettyPrinter { rules, super_selector, }) => { - writeln!( - self.buf, - "{}{} {{", - padding, - super_selector.clone().zip(selector.clone()) - )?; + writeln!(self.buf, "{}{} {{", padding, super_selector.zip(selector))?; self.scope += 1; for rule in rules { self.pretty_print_stmt(rule)?; diff --git a/src/main.rs b/src/main.rs index be51a5a..9f3312e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -405,7 +405,7 @@ impl<'a> StyleSheetParser<'a> { } Expr::Selector(s) => { self.scope += 1; - let rules = self.eat_rules(&super_selector.clone().zip(s.clone()), scope); + let rules = self.eat_rules(&super_selector.zip(&s), scope); stmts.push(Stmt::RuleSet(RuleSet { super_selector: super_selector.clone(), selector: s, @@ -634,7 +634,7 @@ pub(crate) fn eat_expr>( /// Functions that print to stdout or stderr impl<'a> StyleSheetParser<'a> { fn debug(&self, pos: Pos, message: &str) { - println!("{}:{} Debug: {}", self.file, pos.line(), message); + eprintln!("{}:{} Debug: {}", self.file, pos.line(), message); } fn warn(&self, pos: Pos, message: &str) { diff --git a/src/mixin.rs b/src/mixin.rs index 1139c91..e4a821c 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -115,7 +115,7 @@ impl Mixin { Expr::Include(_) | Expr::MixinDecl(_, _) => todo!(), Expr::Selector(s) => { self.nesting += 1; - let rules = self.eval(&super_selector.clone().zip(s.clone()), scope)?; + let rules = self.eval(&super_selector.zip(&s), scope)?; stmts.push(Stmt::RuleSet(RuleSet { super_selector: super_selector.clone(), selector: s, diff --git a/src/selector.rs b/src/selector.rs index 1cc3d78..812f2be 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -268,29 +268,27 @@ impl Selector { SelectorParser::new(scope).all_selectors(tokens) } - pub fn zip(self, other: Selector) -> Selector { + pub fn zip(&self, other: &Selector) -> Selector { if self.0.is_empty() { - return Selector(other.0); + return Selector(other.0.clone()); } let mut rules: Vec = Vec::with_capacity(self.0.len() + other.0.len()); - let sel1_split: Vec> = self + let sel1_split: Vec<&[SelectorKind]> = + self.0.split(|sel| sel == &SelectorKind::Multiple).collect(); + let sel2_split: Vec<&[SelectorKind]> = other .0 .split(|sel| sel == &SelectorKind::Multiple) - .map(|x| x.to_vec()) .collect(); - let sel2_split: Vec> = other - .0 - .split(|sel| sel == &SelectorKind::Multiple) - .map(|x| x.to_vec()) - .collect(); - for (idx, sel1) in sel1_split.iter().enumerate() { + let len1 = sel1_split.len(); + let len2 = sel2_split.len(); + for (idx, sel1) in sel1_split.into_iter().enumerate() { for (idx2, sel2) in sel2_split.iter().enumerate() { - let mut this_selector = Vec::with_capacity(other.0.len()); + let mut this_selector: Vec = Vec::with_capacity(other.0.len()); let mut found_super = false; - for sel in sel2 { + for sel in *sel2 { if sel == &SelectorKind::Super { - this_selector.extend(sel1.iter().cloned()); + this_selector.extend(sel1.to_vec()); found_super = true; } else { this_selector.push(sel.clone()); @@ -298,12 +296,12 @@ impl Selector { } if !found_super { - rules.extend(sel1.iter().cloned()); + rules.extend(sel1.to_vec()); rules.push(SelectorKind::Whitespace); } rules.extend(this_selector); - if !(idx + 1 == sel1_split.len() && idx2 + 1 == sel2_split.len()) { + if !(idx + 1 == len1 && idx2 + 1 == len2) { rules.push(SelectorKind::Multiple); } }