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.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);
|
||||
}
|
||||
|
@ -58,12 +58,7 @@ impl<W: Write> PrettyPrinter<W> {
|
||||
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)?;
|
||||
|
@ -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<I: Iterator<Item = Token>>(
|
||||
/// 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) {
|
||||
|
@ -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,
|
||||
|
@ -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<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
|
||||
.split(|sel| sel == &SelectorKind::Multiple)
|
||||
.map(|x| x.to_vec())
|
||||
.collect();
|
||||
let sel2_split: Vec<Vec<SelectorKind>> = 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<SelectorKind> = 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user