From 1d518efeaf2ad5e24e32a8b3c7bdd8d5a00c5abd Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 30 Apr 2020 19:37:14 -0400 Subject: [PATCH] refactor lowercasing of idents avoid creating more strings than necessary --- src/value/parse.rs | 10 ++++++---- tests/color.rs | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/value/parse.rs b/src/value/parse.rs index 2f081ae..3e2d3f3 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -503,7 +503,9 @@ impl Value { ) -> SassResult { let Spanned { node: mut s, span } = eat_ident(toks, scope, super_selector)?; - if s == "progid" && toks.peek().is_some() && toks.peek().unwrap().kind == ':' { + let lower = s.to_ascii_lowercase(); + + if lower == "progid" && toks.peek().is_some() && toks.peek().unwrap().kind == ':' { toks.next(); s.push(':'); s.push_str(&eat_progid(toks, scope, super_selector)?); @@ -528,7 +530,7 @@ impl Value { })) } None => { - match s.to_ascii_lowercase().as_str() { + match lower.as_str() { "calc" | "element" | "expression" => { s.push_str(&eat_calc_args(toks, scope, super_selector)?) } @@ -557,14 +559,14 @@ impl Value { )); } - if let Some(c) = NAMED_COLORS.get_by_left(&s.as_str()) { + if let Some(c) = NAMED_COLORS.get_by_left(&lower.as_str()) { return Ok(IntermediateValue::Value(Spanned { node: Value::Color(Box::new(Color::new(c[0], c[1], c[2], c[3], s))), span, })); } - Ok(match s.to_ascii_lowercase().as_str() { + Ok(match lower.as_str() { "true" => IntermediateValue::Value(Value::True.span(span)), "false" => IntermediateValue::Value(Value::False.span(span)), "null" => IntermediateValue::Value(Value::Null.span(span)), diff --git a/tests/color.rs b/tests/color.rs index c36db0d..8bd523e 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -4,6 +4,11 @@ mod macros; test!(preserves_named_color_case, "a {\n color: OrAnGe;\n}\n"); +test!( + named_color_casing_is_color, + "a {\n color: hue(RED);\n}\n", + "a {\n color: 0deg;\n}\n" +); test!(preserves_hex_color_case, "a {\n color: #FfFfFf;\n}\n"); test!( preserves_hex_8_val_10000000,