From 2d7aea79b94721362f4fc5285c2a99ab37f52a58 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 13 Sep 2021 01:23:37 +0100 Subject: Make `TypeStructl.tags` a pointer from a slice (reduce memory usage) --- src/check_type.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index 55c931ab4..ccd426322 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -92,7 +92,7 @@ bool does_field_type_allow_using(Type *t) { return false; } -void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, Slice *tags, Slice const ¶ms, +void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, String **tags, Slice const ¶ms, isize init_field_capacity, Type *struct_type, String context) { auto fields_array = array_make(heap_allocator(), 0, init_field_capacity); auto tags_array = array_make(heap_allocator(), 0, init_field_capacity); @@ -184,7 +184,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields } *fields = slice_from_array(fields_array); - *tags = slice_from_array(tags_array); + *tags = tags_array.data; } @@ -2234,7 +2234,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el soa_struct = alloc_type_struct(); soa_struct->Struct.fields = slice_make(heap_allocator(), field_count+extra_field_count); - soa_struct->Struct.tags = slice_make(heap_allocator(), field_count+extra_field_count); + soa_struct->Struct.tags = gb_alloc_array(heap_allocator(), String, field_count+extra_field_count); soa_struct->Struct.node = array_typ_expr; soa_struct->Struct.soa_kind = soa_kind; soa_struct->Struct.soa_elem = elem; @@ -2249,7 +2249,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el soa_struct = alloc_type_struct(); soa_struct->Struct.fields = slice_make(heap_allocator(), field_count+extra_field_count); - soa_struct->Struct.tags = slice_make(heap_allocator(), field_count+extra_field_count); + soa_struct->Struct.tags = gb_alloc_array(heap_allocator(), String, field_count+extra_field_count); soa_struct->Struct.node = array_typ_expr; soa_struct->Struct.soa_kind = soa_kind; soa_struct->Struct.soa_elem = elem; @@ -2291,11 +2291,10 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el Type *old_struct = base_type(elem); field_count = old_struct->Struct.fields.count; - GB_ASSERT(old_struct->Struct.tags.count == field_count); soa_struct = alloc_type_struct(); soa_struct->Struct.fields = slice_make(heap_allocator(), field_count+extra_field_count); - soa_struct->Struct.tags = slice_make(heap_allocator(), field_count+extra_field_count); + soa_struct->Struct.tags = gb_alloc_array(heap_allocator(), String, field_count+extra_field_count); soa_struct->Struct.node = array_typ_expr; soa_struct->Struct.soa_kind = soa_kind; soa_struct->Struct.soa_elem = elem; -- cgit v1.2.3