From 60e817ff3244ccf81148d4af04e782ddd5a64844 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 17 May 2022 17:08:44 +0800 Subject: [PATCH] cgen: minor optimization in index_of_array/map() (#14429) --- vlib/v/gen/c/index.v | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index afdcccbcdd..8af7cca26a 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -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 {