diff --git a/src/value/css_function.rs b/src/value/css_function.rs index 81af526..b543e90 100644 --- a/src/value/css_function.rs +++ b/src/value/css_function.rs @@ -13,42 +13,44 @@ pub(crate) fn eat_calc_args>( toks: &mut PeekMoreIterator, scope: &Scope, super_selector: &Selector, -) -> SassResult { - let mut string = String::from("("); + buf: &mut String, +) -> SassResult<()> { + buf.reserve(2); + buf.push('('); let mut nesting = 0; while let Some(tok) = toks.next() { match tok.kind { ' ' | '\t' | '\n' => { devour_whitespace(toks); - string.push(' '); + buf.push(' '); } '#' => { if toks.peek().is_some() && toks.peek().unwrap().kind == '{' { let span = toks.next().unwrap().pos(); - string.push_str( + buf.push_str( &parse_interpolation(toks, scope, super_selector)?.to_css_string(span)?, ); } else { - string.push('#'); + buf.push('#'); } } '(' => { nesting += 1; - string.push('('); + buf.push('('); } ')' => { if nesting == 0 { break; } else { nesting -= 1; - string.push(')'); + buf.push(')'); } } - c => string.push(c), + c => buf.push(c), } } - string.push(')'); - Ok(string) + buf.push(')'); + Ok(()) } pub(crate) fn is_special_function(s: &str) -> bool { @@ -73,7 +75,7 @@ pub(crate) fn eat_progid>( string.push(tok.kind); } '(' => { - string.push_str(&eat_calc_args(toks, scope, super_selector)?); + eat_calc_args(toks, scope, super_selector, &mut string)?; break; } _ => return Err(("expected \"(\".", span).into()), diff --git a/src/value/parse.rs b/src/value/parse.rs index 720abed..20646c9 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -555,7 +555,7 @@ impl Value { None => { match lower.as_str() { "calc" | "element" | "expression" => { - s.push_str(&eat_calc_args(toks, scope, super_selector)?) + eat_calc_args(toks, scope, super_selector, &mut s)?; } // "min" => {} // "max" => {}