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

cgen: use a temp var in map()

This commit is contained in:
Steve Phillips 2020-05-05 01:29:23 -07:00 committed by GitHub
parent 6aca3be474
commit 84fc587ec2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2576,10 +2576,11 @@ fn (mut g Gen) gen_map(node ast.CallExpr) {
g.expr(node.left)
g.writeln('.len;')
g.writeln('$ret_typ $tmp = __new_array(0, ${tmp}_len, sizeof($ret_elem_type));')
g.writeln('for (int i = 0; i < ${tmp}_len; i++) {')
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; $i++) {')
g.write('\t$inp_elem_type it = (($inp_elem_type*) ')
g.expr(node.left)
g.writeln('.data)[i];')
g.writeln('.data)[$i];')
g.write('\t$ret_elem_type ti = ')
g.expr(node.args[0].expr) // the first arg is the filter condition
g.writeln(';')