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) g.is_shared = var_type.has_flag(.shared_f)
if !cloned { if !cloned {
if is_fixed_array_copy { if is_fixed_array_copy {
i_var := g.new_tmp_var() typ_str := g.typ(val_type).trim('*')
fixed_array := right_sym.info as ast.ArrayFixed ref_str := if val_type.is_ptr() { '' } else { '&' }
g.write('for (int $i_var=0; $i_var<$fixed_array.size; $i_var++) {') g.write('memcpy(($typ_str*)')
g.expr(left) g.expr(left)
g.write('[$i_var] = ') g.write(', (byte*)$ref_str')
if val.is_auto_deref_var() {
g.write('*')
}
g.expr(val) g.expr(val)
g.write('[$i_var];') g.write(', sizeof($typ_str))')
g.writeln('}')
} else if is_decl { } else if is_decl {
if is_fixed_array_init && !has_val { if is_fixed_array_init && !has_val {
if val is ast.ArrayInit { if val is ast.ArrayInit {