From 795a160e019a2d242103252daada0de50e075dac Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 28 Dec 2022 11:03:03 -0500 Subject: [PATCH] remove redundant number accessor --- src/ast/interpolation.rs | 3 --- src/builtin/functions/color/hsl.rs | 10 +++++----- src/builtin/functions/color/opacity.rs | 2 +- src/builtin/functions/math.rs | 2 +- src/builtin/functions/string.rs | 6 +++--- src/evaluate/visitor.rs | 4 ++-- src/value/calculation.rs | 12 ++++++------ src/value/sass_number.rs | 5 ----- 8 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/ast/interpolation.rs b/src/ast/interpolation.rs index a471630..ca0ae00 100644 --- a/src/ast/interpolation.rs +++ b/src/ast/interpolation.rs @@ -1,7 +1,5 @@ use codemap::Spanned; -use crate::token::Token; - use super::AstExpr; #[derive(Debug, Clone)] @@ -36,7 +34,6 @@ impl Interpolation { self.contents.push(InterpolationPart::Expr(expr)); } - // todo: cow? pub fn add_string(&mut self, s: String) { match self.contents.last_mut() { Some(InterpolationPart::String(existing)) => *existing += &s, diff --git a/src/builtin/functions/color/hsl.rs b/src/builtin/functions/color/hsl.rs index 468510b..a8daac0 100644 --- a/src/builtin/functions/color/hsl.rs +++ b/src/builtin/functions/color/hsl.rs @@ -60,9 +60,9 @@ fn hsl_3_args( )?; Ok(Value::Color(Box::new(Color::from_hsla_fn( - Number(hue.num().rem_euclid(360.0)), - saturation.num() / Number(100.0), - lightness.num() / Number(100.0), + Number(hue.num.rem_euclid(360.0)), + saturation.num / Number(100.0), + lightness.num / Number(100.0), Number(alpha), )))) } @@ -179,7 +179,7 @@ pub(crate) fn adjust_hue(mut args: ArgumentResult, visitor: &mut Visitor) -> Sas let degrees = args .get_err(1, "degrees")? .assert_number_with_name("degrees", args.span())? - .num(); + .num; Ok(Value::Color(Box::new(color.adjust_hue(degrees)))) } @@ -200,7 +200,7 @@ fn lighten(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult let amount = args .get_err(1, "amount")? .assert_number_with_name("amount", args.span())?; - let amount = bound!(args, "amount", amount.num(), amount.unit, 0, 100) / Number(100.0); + let amount = bound!(args, "amount", amount.num, amount.unit, 0, 100) / Number(100.0); Ok(Value::Color(Box::new(color.lighten(amount)))) } diff --git a/src/builtin/functions/color/opacity.rs b/src/builtin/functions/color/opacity.rs index 60f284a..8d4aa26 100644 --- a/src/builtin/functions/color/opacity.rs +++ b/src/builtin/functions/color/opacity.rs @@ -109,7 +109,7 @@ fn opacify(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult .get_err(1, "amount")? .assert_number_with_name("amount", args.span())?; - let amount = bound!(args, "amount", amount.num(), amount.unit(), 0, 1); + let amount = bound!(args, "amount", amount.num, amount.unit(), 0, 1); Ok(Value::Color(Box::new(color.fade_in(amount)))) } diff --git a/src/builtin/functions/math.rs b/src/builtin/functions/math.rs index ec17da2..fd8e68b 100644 --- a/src/builtin/functions/math.rs +++ b/src/builtin/functions/math.rs @@ -127,7 +127,7 @@ pub(crate) fn random(mut args: ArgumentResult, visitor: &mut Visitor) -> SassRes })); } - let limit = limit.assert_number_with_name("limit", args.span())?.num(); + let limit = limit.assert_number_with_name("limit", args.span())?.num; let limit_int = limit.assert_int_with_name("limit", args.span())?; if limit.is_one() { diff --git a/src/builtin/functions/string.rs b/src/builtin/functions/string.rs index f0daa45..3d8375c 100644 --- a/src/builtin/functions/string.rs +++ b/src/builtin/functions/string.rs @@ -93,7 +93,7 @@ pub(crate) fn str_slice(mut args: ArgumentResult, visitor: &mut Visitor) -> Sass .assert_number_with_name("start-at", span)?; start.assert_no_units("start-at", span)?; - let start = start.num().assert_int(span)?; + let start = start.num.assert_int(span)?; let start = if start == 0 { 1 @@ -117,7 +117,7 @@ pub(crate) fn str_slice(mut args: ArgumentResult, visitor: &mut Visitor) -> Sass end.assert_no_units("end-at", span)?; - let mut end = end.num().assert_int(span)?; + let mut end = end.num.assert_int(span)?; if end < 0 { end += str_len as i64 + 1; @@ -203,7 +203,7 @@ pub(crate) fn str_insert(mut args: ArgumentResult, visitor: &mut Visitor) -> Sas .get_err(2, "index")? .assert_number_with_name("index", span)?; index.assert_no_units("index", span)?; - let index_int = index.num().assert_int_with_name("index", span)?; + let index_int = index.num.assert_int_with_name("index", span)?; if s1.is_empty() { return Ok(Value::String(substr, quotes)); diff --git a/src/evaluate/visitor.rs b/src/evaluate/visitor.rs index 9871e06..e614fdb 100644 --- a/src/evaluate/visitor.rs +++ b/src/evaluate/visitor.rs @@ -1703,9 +1703,9 @@ impl<'a> Visitor<'a> { .into()); } - let from = from_number.num().assert_int(from_span)?; + let from = from_number.num.assert_int(from_span)?; let mut to = to_number - .num() + .num .convert(to_number.unit(), from_number.unit()) .assert_int(to_span)?; diff --git a/src/value/calculation.rs b/src/value/calculation.rs index e5e73bc..b086376 100644 --- a/src/value/calculation.rs +++ b/src/value/calculation.rs @@ -101,8 +101,8 @@ impl SassCalculation { } CalculationArg::Number(n) if minimum.is_none() - || minimum.as_ref().unwrap().num() - > n.num().convert(&n.unit, &minimum.as_ref().unwrap().unit) => + || minimum.as_ref().unwrap().num + > n.num.convert(&n.unit, &minimum.as_ref().unwrap().unit) => { minimum = Some(n.clone()); } @@ -145,8 +145,8 @@ impl SassCalculation { } CalculationArg::Number(n) if maximum.is_none() - || maximum.as_ref().unwrap().num() - < n.num().convert(&n.unit, &maximum.as_ref().unwrap().unit) => + || maximum.as_ref().unwrap().num + < n.num.convert(&n.unit, &maximum.as_ref().unwrap().unit) => { maximum = Some(n.clone()); } @@ -193,11 +193,11 @@ impl SassCalculation { Some(CalculationArg::Number(max)), ) => { if min.is_comparable_to(&value) && min.is_comparable_to(&max) { - if value.num <= min.num().convert(min.unit(), value.unit()) { + if value.num <= min.num.convert(min.unit(), value.unit()) { return Ok(Value::Dimension(min)); } - if value.num >= max.num().convert(max.unit(), value.unit()) { + if value.num >= max.num.convert(max.unit(), value.unit()) { return Ok(Value::Dimension(max)); } diff --git a/src/value/sass_number.rs b/src/value/sass_number.rs index 9326961..b18f966 100644 --- a/src/value/sass_number.rs +++ b/src/value/sass_number.rs @@ -178,11 +178,6 @@ impl SassNumber { || known_compatibilities_by_unit(&other.unit).is_none() } - // todo: remove - pub fn num(&self) -> Number { - self.num - } - // todo: remove pub fn unit(&self) -> &Unit { &self.unit