parser: minor optimization of array filtering judgement (#10821)

pull/10833/head
yuyi 2021-07-16 17:00:37 +08:00 committed by GitHub
parent 6892f67a04
commit fe64346ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -36,7 +36,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
ident := p.parse_ident(ast.Language.v) ident := p.parse_ident(ast.Language.v)
node = ident node = ident
if p.inside_defer { if p.inside_defer {
if p.defer_vars.filter(it.name == ident.name && it.mod == ident.mod).len == 0 if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
&& ident.name != 'err' { && ident.name != 'err' {
p.defer_vars << ident p.defer_vars << ident
} }

View File

@ -2055,8 +2055,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
ident := p.parse_ident(language) ident := p.parse_ident(language)
node = ident node = ident
if p.inside_defer { if p.inside_defer {
if p.defer_vars.filter(it.name == ident.name if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
&& it.mod == ident.mod).len == 0 && ident.name != 'err' { && ident.name != 'err' {
p.defer_vars << ident p.defer_vars << ident
} }
} }
@ -2085,7 +2085,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
ident := p.parse_ident(language) ident := p.parse_ident(language)
node = ident node = ident
if p.inside_defer { if p.inside_defer {
if p.defer_vars.filter(it.name == ident.name && it.mod == ident.mod).len == 0 if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
&& ident.name != 'err' { && ident.name != 'err' {
p.defer_vars << ident p.defer_vars << ident
} }
@ -2197,7 +2197,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
ident := p.parse_ident(language) ident := p.parse_ident(language)
node = ident node = ident
if p.inside_defer { if p.inside_defer {
if p.defer_vars.filter(it.name == ident.name && it.mod == ident.mod).len == 0 if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
&& ident.name != 'err' { && ident.name != 'err' {
p.defer_vars << ident p.defer_vars << ident
} }
@ -2354,7 +2354,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
concrete_list_pos = concrete_list_pos.extend(p.prev_tok.position()) concrete_list_pos = concrete_list_pos.extend(p.prev_tok.position())
// In case of `foo<T>()` // In case of `foo<T>()`
// T is unwrapped and registered in the checker. // T is unwrapped and registered in the checker.
has_generic := concrete_types.filter(it.has_flag(.generic)).len > 0 has_generic := concrete_types.any(it.has_flag(.generic))
if !has_generic { if !has_generic {
// will be added in checker // will be added in checker
p.table.register_fn_concrete_types(field_name, concrete_types) p.table.register_fn_concrete_types(field_name, concrete_types)