cgen: minor optimization of fixed array copy (#9554)

pull/9562/head
yuyi 2021-04-02 07:58:20 +08:00 committed by GitHub
parent d8efe249ce
commit c11356be21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 9 deletions

View File

@ -2427,17 +2427,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.is_shared = var_type.has_flag(.shared_f)
if !cloned {
if is_fixed_array_copy {
i_var := g.new_tmp_var()
fixed_array := right_sym.info as ast.ArrayFixed
g.write('for (int $i_var=0; $i_var<$fixed_array.size; $i_var++) {')
typ_str := g.typ(val_type).trim('*')
ref_str := if val_type.is_ptr() { '' } else { '&' }
g.write('memcpy(($typ_str*)')
g.expr(left)
g.write('[$i_var] = ')
if val.is_auto_deref_var() {
g.write('*')
}
g.write(', (byte*)$ref_str')
g.expr(val)
g.write('[$i_var];')
g.writeln('}')
g.write(', sizeof($typ_str))')
} else if is_decl {
if is_fixed_array_init && !has_val {
if val is ast.ArrayInit {