Skip to content

Commit

Permalink
perf(css/parser): Reduce number of function calls (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 7, 2022
1 parent 259eb87 commit 252edb5
Show file tree
Hide file tree
Showing 11 changed files with 2,078 additions and 166 deletions.
186 changes: 77 additions & 109 deletions crates/swc_css_parser/src/lexer/mod.rs

Large diffs are not rendered by default.

64 changes: 24 additions & 40 deletions crates/swc_css_parser/src/macros.rs
Expand Up @@ -35,12 +35,12 @@ macro_rules! tok {
swc_css_ast::Token::BadUrl { .. }
};

("[") => {
swc_css_ast::Token::LBracket
("{") => {
swc_css_ast::Token::LBrace
};

("]") => {
swc_css_ast::Token::RBracket
("}") => {
swc_css_ast::Token::RBrace
};

("(") => {
Expand All @@ -51,8 +51,12 @@ macro_rules! tok {
swc_css_ast::Token::RParen
};

("%") => {
swc_css_ast::Token::Delim { value: '%', .. }
("[") => {
swc_css_ast::Token::LBracket
};

("]") => {
swc_css_ast::Token::RBracket
};

(",") => {
Expand All @@ -63,36 +67,16 @@ macro_rules! tok {
swc_css_ast::Token::Semi
};

("!") => {
swc_css_ast::Token::Delim { value: '!', .. }
};

("?") => {
swc_css_ast::Token::Delim { value: '?', .. }
};

("{") => {
swc_css_ast::Token::LBrace
};

("}") => {
swc_css_ast::Token::RBrace
};

("[") => {
swc_css_ast::Token::LBracket
};

("]") => {
swc_css_ast::Token::RBracket
swc_css_ast::Token::Delim { value: '?' }
};

(":") => {
swc_css_ast::Token::Colon
};

("*") => {
swc_css_ast::Token::Delim { value: '*', .. }
swc_css_ast::Token::Delim { value: '*' }
};

("@") => {
Expand All @@ -104,27 +88,27 @@ macro_rules! tok {
};

("&") => {
swc_css_ast::Token::Delim { value: '&', .. }
swc_css_ast::Token::Delim { value: '&' }
};

("|") => {
swc_css_ast::Token::Delim { value: '|', .. }
swc_css_ast::Token::Delim { value: '|' }
};

("$") => {
swc_css_ast::Token::Delim { value: '$', .. }
swc_css_ast::Token::Delim { value: '$' }
};

("^") => {
swc_css_ast::Token::Delim { value: '^', .. }
swc_css_ast::Token::Delim { value: '^' }
};

("~") => {
swc_css_ast::Token::Delim { value: '~', .. }
swc_css_ast::Token::Delim { value: '~' }
};

("=") => {
swc_css_ast::Token::Delim { value: '=', .. }
swc_css_ast::Token::Delim { value: '=' }
};

(" ") => {
Expand All @@ -140,26 +124,26 @@ macro_rules! tok {
};

("+") => {
swc_css_ast::Token::Delim { value: '+', .. }
swc_css_ast::Token::Delim { value: '+' }
};

("-") => {
swc_css_ast::Token::Delim { value: '-', .. }
swc_css_ast::Token::Delim { value: '-' }
};

(".") => {
swc_css_ast::Token::Delim { value: '.', .. }
swc_css_ast::Token::Delim { value: '.' }
};

("/") => {
swc_css_ast::Token::Delim { value: '/', .. }
swc_css_ast::Token::Delim { value: '/' }
};

("<") => {
swc_css_ast::Token::Delim { value: '<', .. }
swc_css_ast::Token::Delim { value: '<' }
};

(">") => {
swc_css_ast::Token::Delim { value: '>', .. }
swc_css_ast::Token::Delim { value: '>' }
};
}
6 changes: 6 additions & 0 deletions crates/swc_css_parser/tests/fixture/value/ident/input.css
@@ -0,0 +1,6 @@
a { animation: test; }
a { animation: тест; }
a { animation: т\ест; }
a { animation: 😋; }
a { animation: \\😋; }
a { animation: \😋; }

0 comments on commit 252edb5

Please sign in to comment.