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

cgen: honor [direct_array_access] for a_string[idx] too

This commit is contained in:
Delyan Angelov 2021-05-05 23:43:46 +03:00
parent fc801fd563
commit ab39011fb9
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -18,11 +18,19 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
} else if sym.kind == .map {
g.index_of_map(node, sym)
} else if sym.kind == .string && !node.left_type.is_ptr() {
g.write('string_at(')
g.expr(node.left)
g.write(', ')
g.expr(node.index)
g.write(')')
is_direct_array_access := g.fn_decl != 0 && g.fn_decl.is_direct_arr
if is_direct_array_access {
g.expr(node.left)
g.write('.str[ ')
g.expr(node.index)
g.write(']')
} else {
g.write('string_at(')
g.expr(node.left)
g.write(', ')
g.expr(node.index)
g.write(')')
}
} else {
g.expr(node.left)
g.write('[')