cgen: minor optimization in index_of_array/map() (#14429)
parent
d6aa85d059
commit
60e817ff32
|
@ -164,11 +164,12 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
|||
gen_or := node.or_expr.kind != .absent || node.is_option
|
||||
left_is_ptr := node.left_type.is_ptr()
|
||||
info := sym.info as ast.Array
|
||||
mut elem_type_str := g.typ(info.elem_type)
|
||||
elem_type := info.elem_type
|
||||
elem_sym := g.table.sym(elem_type)
|
||||
if elem_sym.kind == .function {
|
||||
elem_type_str = 'voidptr'
|
||||
elem_type_str := if elem_sym.kind == .function {
|
||||
'voidptr'
|
||||
} else {
|
||||
g.typ(info.elem_type)
|
||||
}
|
||||
// `vals[i].field = x` is an exception and requires `array_get`:
|
||||
// `(*(Val*)array_get(vals, i)).field = x;`
|
||||
|
@ -355,10 +356,11 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
|
|||
info := sym.info as ast.Map
|
||||
key_type_str := g.typ(info.key_type)
|
||||
elem_type := info.value_type
|
||||
mut elem_type_str := g.typ(elem_type)
|
||||
elem_sym := g.table.sym(elem_type)
|
||||
if elem_sym.kind == .function {
|
||||
elem_type_str = 'voidptr'
|
||||
elem_type_str := if elem_sym.kind == .function {
|
||||
'voidptr'
|
||||
} else {
|
||||
g.typ(elem_type)
|
||||
}
|
||||
get_and_set_types := elem_sym.kind in [.struct_, .map]
|
||||
if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types {
|
||||
|
|
Loading…
Reference in New Issue