From d2af63ed314ad428a2cc546fa8d7bfea9e6d77b1 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Tue, 26 May 2020 15:32:41 +0800 Subject: [PATCH 1/5] refactor media conditional --- src/atrule/media.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/atrule/media.rs b/src/atrule/media.rs index 70dd2d1..99e3f10 100644 --- a/src/atrule/media.rs +++ b/src/atrule/media.rs @@ -64,9 +64,7 @@ impl Media { } } - if super_selector.is_empty() { - body.append(&mut rules); - } else { + if !super_selector.is_empty() { body = vec![Spanned { node: Stmt::RuleSet(RuleSet { selector: super_selector.clone(), @@ -75,8 +73,8 @@ impl Media { }), span: kind_span, }]; - body.append(&mut rules); } + body.append(&mut rules); Ok(Media { super_selector: Selector::new(), From 3741b312ab60b2f0a38a7462cc24c8b4b91e337d Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 26 May 2020 15:46:02 +0200 Subject: [PATCH 2/5] Add CI workflows --- .github/workflows/tests.yml | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1000426 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,81 @@ +name: CI +on: + push: + branches: + - master + pull_request: + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: version info + run: rustc --version; cargo --version; + + - name: Run all tests + run: cargo test + + fmt: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings + + + sass-spec: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: version info + run: rustc --version; cargo --version; + + - name: Build binary + run: cargo b --release + + - name: Run Sass spec + run: ./sass-spec/sass-spec.rb -c './target/release/grass' From 9ae3ce52be86bda1072d836c117b1047f8ee5385 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 26 May 2020 15:51:15 +0200 Subject: [PATCH 3/5] Fix fmt + sass --- .github/workflows/tests.yml | 10 ++++++++++ .gitignore | 2 ++ input.scss | 3 +++ src/args.rs | 2 +- src/utils/strings.rs | 2 +- src/value/ops.rs | 4 +++- 6 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 input.scss diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1000426..8a21474 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,6 +60,7 @@ jobs: sass-spec: + continue-on-error: true runs-on: ubuntu-latest steps: - name: Checkout @@ -77,5 +78,14 @@ jobs: - name: Build binary run: cargo b --release + - name: Get sass-spec + run: git submodule init && git submodule update + + - name: Install whatever Ruby needs + run: | + sudo apt-get install libncurses5-dev libncursesw5-dev + sudo gem install bundler + cd sass-spec && bundler install + - name: Run Sass spec run: ./sass-spec/sass-spec.rb -c './target/release/grass' diff --git a/.gitignore b/.gitignore index c08fa70..2089ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ Cargo.lock coverage pkg +.idea/ +!input.scss \ No newline at end of file diff --git a/input.scss b/input.scss new file mode 100644 index 0000000..80afe79 --- /dev/null +++ b/input.scss @@ -0,0 +1,3 @@ +body { + background: red; +} \ No newline at end of file diff --git a/src/args.rs b/src/args.rs index 0ae0583..7cf5e38 100644 --- a/src/args.rs +++ b/src/args.rs @@ -5,7 +5,6 @@ use codemap::{Span, Spanned}; use peekmore::PeekMoreIterator; -use crate::Cow; use crate::common::Identifier; use crate::error::SassResult; use crate::scope::Scope; @@ -15,6 +14,7 @@ use crate::utils::{ read_until_closing_paren, read_until_closing_quote, read_until_closing_square_brace, }; use crate::value::Value; +use crate::Cow; use crate::Token; #[derive(Debug, Clone, Eq, PartialEq)] diff --git a/src/utils/strings.rs b/src/utils/strings.rs index 4573941..9eda2e5 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -1,5 +1,5 @@ -use std::iter::Iterator; use std::borrow::Borrow; +use std::iter::Iterator; use codemap::{Span, Spanned}; diff --git a/src/value/ops.rs b/src/value/ops.rs index 6b71dc5..254ab8c 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -268,7 +268,9 @@ impl Value { format!("{}{}", self.to_css_string(span)?, s), QuoteKind::Quoted, ), - Self::Null => Value::String(self.to_css_string(span)?.into_owned(), QuoteKind::None), + Self::Null => { + Value::String(self.to_css_string(span)?.into_owned(), QuoteKind::None) + } _ => Value::String( format!( "{}{}", From e9ffaa579e4cec50d246b0dd9e4027aed29713ef Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 26 May 2020 23:38:24 -0400 Subject: [PATCH 4/5] use ad hoc parser for small integers this results in about a 3% speed up for small integer and float parsing --- src/value/parse.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/value/parse.rs b/src/value/parse.rs index 7c49e53..96f347a 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -431,6 +431,17 @@ fn single_value>( }) } +/// Parse numbers from strings *known* to contain +/// only the characters 0-9 +fn parse_i64(s: String) -> i64 { + let mut output = 0i64; + for b in s.as_bytes() { + output *= 10; + output += i64::from(b - b'0'); + } + output +} + impl Value { pub fn from_tokens>( toks: &mut PeekMoreIterator, @@ -735,7 +746,7 @@ impl Value { let n = if val.dec_len == 0 { if val.num.len() <= 18 && val.times_ten.is_empty() { - let n = Rational64::new_raw(val.num.parse::().unwrap(), 1); + let n = Rational64::new_raw(parse_i64(val.num), 1); return Some(Ok(IntermediateValue::Value(Value::Dimension( Number::new_machine(n), unit, @@ -746,7 +757,7 @@ impl Value { } else { if val.num.len() <= 18 && val.times_ten.is_empty() { let n = - Rational64::new(val.num.parse::().unwrap(), pow(10, val.dec_len)); + Rational64::new(parse_i64(val.num), pow(10, val.dec_len)); return Some(Ok(IntermediateValue::Value(Value::Dimension( Number::new_machine(n), unit, From b658369e8aea98aed322838339265ec90dbc9929 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Wed, 27 May 2020 13:53:47 -0400 Subject: [PATCH 5/5] use fold instead of for loop --- src/value/parse.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/value/parse.rs b/src/value/parse.rs index 96f347a..5e818fe 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -431,15 +431,10 @@ fn single_value>( }) } -/// Parse numbers from strings *known* to contain -/// only the characters 0-9 fn parse_i64(s: String) -> i64 { - let mut output = 0i64; - for b in s.as_bytes() { - output *= 10; - output += i64::from(b - b'0'); - } - output + s.as_bytes() + .iter() + .fold(0, |total, this| total * 10 + i64::from(this - b'0')) } impl Value { @@ -756,8 +751,7 @@ impl Value { BigRational::new_raw(val.num.parse::().unwrap(), BigInt::one()) } else { if val.num.len() <= 18 && val.times_ten.is_empty() { - let n = - Rational64::new(parse_i64(val.num), pow(10, val.dec_len)); + let n = Rational64::new(parse_i64(val.num), pow(10, val.dec_len)); return Some(Ok(IntermediateValue::Value(Value::Dimension( Number::new_machine(n), unit,