cgen: minor optimization to `for ch in "StringLiteral"` (#9240)
parent
a547e889af
commit
8de6511056
|
@ -1509,13 +1509,18 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
|
|||
}
|
||||
}
|
||||
} else if node.kind == .string {
|
||||
cond := if node.cond is ast.StringLiteral || node.cond is ast.StringInterLiteral {
|
||||
ast.Expr(g.new_ctemp_var_then_gen(node.cond, table.string_type))
|
||||
} else {
|
||||
node.cond
|
||||
}
|
||||
i := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
|
||||
g.write('for (int $i = 0; $i < ')
|
||||
g.expr(node.cond)
|
||||
g.expr(cond)
|
||||
g.writeln('.len; ++$i) {')
|
||||
if node.val_var != '_' {
|
||||
g.write('\tbyte ${c_name(node.val_var)} = ')
|
||||
g.expr(node.cond)
|
||||
g.expr(cond)
|
||||
g.writeln('.str[$i];')
|
||||
}
|
||||
} else if node.kind == .struct_ {
|
||||
|
|
Loading…
Reference in New Issue