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:
parent
fc801fd563
commit
ab39011fb9
@ -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('[')
|
||||
|
Loading…
Reference in New Issue
Block a user