Further reduce usage of .clone()
This commit is contained in:
parent
720b1e9f22
commit
b25fe63e8e
@ -100,7 +100,7 @@ impl Css {
|
|||||||
self.idx = self.blocks.len() + 1;
|
self.idx = self.blocks.len() + 1;
|
||||||
self.inner_rulesets = 0;
|
self.inner_rulesets = 0;
|
||||||
self.blocks
|
self.blocks
|
||||||
.push(Toplevel::new_rule(super_selector.zip(selector)));
|
.push(Toplevel::new_rule(super_selector.zip(&selector)));
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
self.at_root = true;
|
self.at_root = true;
|
||||||
self.parse_stmt(rule);
|
self.parse_stmt(rule);
|
||||||
@ -111,7 +111,7 @@ impl Css {
|
|||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
self.at_root = false;
|
self.at_root = false;
|
||||||
self.blocks
|
self.blocks
|
||||||
.push(Toplevel::new_rule(super_selector.zip(selector)));
|
.push(Toplevel::new_rule(super_selector.zip(&selector)));
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
self.parse_stmt(rule);
|
self.parse_stmt(rule);
|
||||||
}
|
}
|
||||||
|
@ -58,12 +58,7 @@ impl<W: Write> PrettyPrinter<W> {
|
|||||||
rules,
|
rules,
|
||||||
super_selector,
|
super_selector,
|
||||||
}) => {
|
}) => {
|
||||||
writeln!(
|
writeln!(self.buf, "{}{} {{", padding, super_selector.zip(selector))?;
|
||||||
self.buf,
|
|
||||||
"{}{} {{",
|
|
||||||
padding,
|
|
||||||
super_selector.clone().zip(selector.clone())
|
|
||||||
)?;
|
|
||||||
self.scope += 1;
|
self.scope += 1;
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
self.pretty_print_stmt(rule)?;
|
self.pretty_print_stmt(rule)?;
|
||||||
|
@ -405,7 +405,7 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
}
|
}
|
||||||
Expr::Selector(s) => {
|
Expr::Selector(s) => {
|
||||||
self.scope += 1;
|
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 {
|
stmts.push(Stmt::RuleSet(RuleSet {
|
||||||
super_selector: super_selector.clone(),
|
super_selector: super_selector.clone(),
|
||||||
selector: s,
|
selector: s,
|
||||||
@ -634,7 +634,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
|||||||
/// Functions that print to stdout or stderr
|
/// Functions that print to stdout or stderr
|
||||||
impl<'a> StyleSheetParser<'a> {
|
impl<'a> StyleSheetParser<'a> {
|
||||||
fn debug(&self, pos: Pos, message: &str) {
|
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) {
|
fn warn(&self, pos: Pos, message: &str) {
|
||||||
|
@ -115,7 +115,7 @@ impl Mixin {
|
|||||||
Expr::Include(_) | Expr::MixinDecl(_, _) => todo!(),
|
Expr::Include(_) | Expr::MixinDecl(_, _) => todo!(),
|
||||||
Expr::Selector(s) => {
|
Expr::Selector(s) => {
|
||||||
self.nesting += 1;
|
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 {
|
stmts.push(Stmt::RuleSet(RuleSet {
|
||||||
super_selector: super_selector.clone(),
|
super_selector: super_selector.clone(),
|
||||||
selector: s,
|
selector: s,
|
||||||
|
@ -268,29 +268,27 @@ impl Selector {
|
|||||||
SelectorParser::new(scope).all_selectors(tokens)
|
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() {
|
if self.0.is_empty() {
|
||||||
return Selector(other.0);
|
return Selector(other.0.clone());
|
||||||
}
|
}
|
||||||
let mut rules: Vec<SelectorKind> = Vec::with_capacity(self.0.len() + other.0.len());
|
let mut rules: Vec<SelectorKind> = Vec::with_capacity(self.0.len() + other.0.len());
|
||||||
let sel1_split: Vec<Vec<SelectorKind>> = self
|
let sel1_split: Vec<&[SelectorKind]> =
|
||||||
|
self.0.split(|sel| sel == &SelectorKind::Multiple).collect();
|
||||||
|
let sel2_split: Vec<&[SelectorKind]> = other
|
||||||
.0
|
.0
|
||||||
.split(|sel| sel == &SelectorKind::Multiple)
|
.split(|sel| sel == &SelectorKind::Multiple)
|
||||||
.map(|x| x.to_vec())
|
|
||||||
.collect();
|
.collect();
|
||||||
let sel2_split: Vec<Vec<SelectorKind>> = other
|
let len1 = sel1_split.len();
|
||||||
.0
|
let len2 = sel2_split.len();
|
||||||
.split(|sel| sel == &SelectorKind::Multiple)
|
for (idx, sel1) in sel1_split.into_iter().enumerate() {
|
||||||
.map(|x| x.to_vec())
|
|
||||||
.collect();
|
|
||||||
for (idx, sel1) in sel1_split.iter().enumerate() {
|
|
||||||
for (idx2, sel2) in sel2_split.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<SelectorKind> = Vec::with_capacity(other.0.len());
|
||||||
let mut found_super = false;
|
let mut found_super = false;
|
||||||
|
|
||||||
for sel in sel2 {
|
for sel in *sel2 {
|
||||||
if sel == &SelectorKind::Super {
|
if sel == &SelectorKind::Super {
|
||||||
this_selector.extend(sel1.iter().cloned());
|
this_selector.extend(sel1.to_vec());
|
||||||
found_super = true;
|
found_super = true;
|
||||||
} else {
|
} else {
|
||||||
this_selector.push(sel.clone());
|
this_selector.push(sel.clone());
|
||||||
@ -298,12 +296,12 @@ impl Selector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found_super {
|
if !found_super {
|
||||||
rules.extend(sel1.iter().cloned());
|
rules.extend(sel1.to_vec());
|
||||||
rules.push(SelectorKind::Whitespace);
|
rules.push(SelectorKind::Whitespace);
|
||||||
}
|
}
|
||||||
rules.extend(this_selector);
|
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);
|
rules.push(SelectorKind::Multiple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user