1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: move var decl out of loop in global_decl()

This commit is contained in:
Joe Conigliaro 2022-02-18 00:42:54 +11:00
parent ebb66aa82c
commit d739abbb3f
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -4311,6 +4311,9 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
} else {
''
}
// should the global be initialized now
should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module)
|| (g.pref.build_mode == .build_module && g.module_built == node.mod)
mut attributes := ''
if node.attrs.contains('weak') {
attributes += 'VWEAK '
@ -4325,8 +4328,6 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
}
}
styp := g.typ(field.typ)
should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module)
|| (g.pref.build_mode == .build_module && g.module_built == node.mod)
g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
if field.has_expr {
if field.expr.is_literal() && should_init {