v.parser: let fn_decl use 1 loop, instead of multiple p.attrs.contains calls

pull/10182/head
Delyan Angelov 2021-05-23 16:54:12 +03:00
parent bf3af40f13
commit e9fa53b0c1
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 21 additions and 7 deletions

View File

@ -174,13 +174,27 @@ mut:
fn (mut p Parser) fn_decl() ast.FnDecl { fn (mut p Parser) fn_decl() ast.FnDecl {
p.top_level_statement_start() p.top_level_statement_start()
start_pos := p.tok.position() start_pos := p.tok.position()
is_manualfree := p.is_manualfree || p.attrs.contains('manualfree')
is_deprecated := p.attrs.contains('deprecated') mut is_manualfree := p.is_manualfree
is_direct_arr := p.attrs.contains('direct_array_access') mut is_deprecated := false
mut is_direct_arr := false
mut is_keep_alive := false
mut is_exported := false
mut is_unsafe := false
mut is_trusted := false
for fna in p.attrs {
match fna.name {
'manualfree' { is_manualfree = true }
'deprecated' { is_deprecated = true }
'direct_array_access' { is_direct_arr = true }
'keep_args_alive' { is_keep_alive = true }
'export' { is_exported = true }
'unsafe' { is_unsafe = true }
'trusted' { is_trusted = true }
else {}
}
}
conditional_ctdefine := p.attrs.find_comptime_define() or { '' } conditional_ctdefine := p.attrs.find_comptime_define() or { '' }
mut is_unsafe := p.attrs.contains('unsafe')
is_keep_alive := p.attrs.contains('keep_args_alive')
is_exported := p.attrs.contains('export')
is_pub := p.tok.kind == .key_pub is_pub := p.tok.kind == .key_pub
if is_pub { if is_pub {
p.next() p.next()
@ -190,7 +204,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
// C. || JS. // C. || JS.
mut language := ast.Language.v mut language := ast.Language.v
if p.tok.kind == .name && p.tok.lit == 'C' { if p.tok.kind == .name && p.tok.lit == 'C' {
is_unsafe = !p.attrs.contains('trusted') is_unsafe = !is_trusted
language = ast.Language.c language = ast.Language.c
} else if p.tok.kind == .name && p.tok.lit == 'JS' { } else if p.tok.kind == .name && p.tok.lit == 'JS' {
language = ast.Language.js language = ast.Language.js