Skip to content

Commit

Permalink
parser: improve performance for language parsing (#20190)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 15, 2023
1 parent 6d0d82d commit 1cdd6ed
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions vlib/v/parser/parse_type.v
Expand Up @@ -326,12 +326,22 @@ fn (mut p Parser) parse_type_with_mut(is_mut bool) ast.Type {
}

// Parses any language indicators on a type.
@[direct_array_access]
fn (mut p Parser) parse_language() ast.Language {
language := match p.tok.lit {
'C' { ast.Language.c }
'JS' { ast.Language.js }
'WASM' { ast.Language.wasm }
else { ast.Language.v }
language := match true {
p.tok.lit.len == 1 && p.tok.lit[0] == `C` {
ast.Language.c
}
p.tok.lit.len == 2 && p.tok.lit[0] == `J` && p.tok.lit[1] == `S` {
ast.Language.js
}
p.tok.lit.len == 4 && p.tok.lit[0] == `W` && p.tok.lit[1] == `A` && p.tok.lit[2] == `S`
&& p.tok.lit[3] == `M` {
ast.Language.wasm
}
else {
ast.Language.v
}
}
if language != .v {
p.next()
Expand Down

0 comments on commit 1cdd6ed

Please sign in to comment.