mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-09 21:11:36 -07:00
Make TypeStructl.tags a pointer from a slice (reduce memory usage)
This commit is contained in:
@@ -1789,7 +1789,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
||||
elem = alloc_type_struct();
|
||||
elem->Struct.scope = s;
|
||||
elem->Struct.fields = slice_from_array(fields);
|
||||
elem->Struct.tags = slice_make<String>(permanent_allocator(), fields.count);
|
||||
elem->Struct.tags = gb_alloc_array(permanent_allocator(), String, fields.count);
|
||||
elem->Struct.node = dummy_node_struct;
|
||||
type_set_offsets(elem);
|
||||
}
|
||||
@@ -1939,7 +1939,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
||||
Type *old_array = base_type(elem);
|
||||
soa_struct = alloc_type_struct();
|
||||
soa_struct->Struct.fields = slice_make<Entity *>(heap_allocator(), cast(isize)old_array->Array.count);
|
||||
soa_struct->Struct.tags = slice_make<String>(heap_allocator(), cast(isize)old_array->Array.count);
|
||||
soa_struct->Struct.tags = gb_alloc_array(permanent_allocator(), String, cast(isize)old_array->Array.count);
|
||||
soa_struct->Struct.node = operand->expr;
|
||||
soa_struct->Struct.soa_kind = StructSoa_Fixed;
|
||||
soa_struct->Struct.soa_elem = elem;
|
||||
@@ -1972,7 +1972,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
|
||||
Type *old_struct = base_type(elem);
|
||||
soa_struct = alloc_type_struct();
|
||||
soa_struct->Struct.fields = slice_make<Entity *>(heap_allocator(), old_struct->Struct.fields.count);
|
||||
soa_struct->Struct.tags = slice_make<String>(heap_allocator(), old_struct->Struct.tags.count);
|
||||
soa_struct->Struct.tags = gb_alloc_array(permanent_allocator(), String, old_struct->Struct.fields.count);
|
||||
soa_struct->Struct.node = operand->expr;
|
||||
soa_struct->Struct.soa_kind = StructSoa_Fixed;
|
||||
soa_struct->Struct.soa_elem = elem;
|
||||
|
||||
+5
-6
@@ -92,7 +92,7 @@ bool does_field_type_allow_using(Type *t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields, Slice<String> *tags, Slice<Ast *> const ¶ms,
|
||||
void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields, String **tags, Slice<Ast *> const ¶ms,
|
||||
isize init_field_capacity, Type *struct_type, String context) {
|
||||
auto fields_array = array_make<Entity *>(heap_allocator(), 0, init_field_capacity);
|
||||
auto tags_array = array_make<String>(heap_allocator(), 0, init_field_capacity);
|
||||
@@ -184,7 +184,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *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<Entity *>(heap_allocator(), field_count+extra_field_count);
|
||||
soa_struct->Struct.tags = slice_make<String>(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<Entity *>(heap_allocator(), field_count+extra_field_count);
|
||||
soa_struct->Struct.tags = slice_make<String>(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<Entity *>(heap_allocator(), field_count+extra_field_count);
|
||||
soa_struct->Struct.tags = slice_make<String>(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;
|
||||
|
||||
@@ -721,7 +721,7 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
|
||||
lb_emit_store(p, offset, lb_const_int(m, t_uintptr, foffset));
|
||||
lb_emit_store(p, is_using, lb_const_bool(m, t_bool, (f->flags&EntityFlag_Using) != 0));
|
||||
|
||||
if (t->Struct.tags.count > 0) {
|
||||
if (t->Struct.tags != nullptr) {
|
||||
String tag_string = t->Struct.tags[source_index];
|
||||
if (tag_string.len > 0) {
|
||||
lbValue tag_ptr = lb_emit_ptr_offset(p, memory_tags, index);
|
||||
|
||||
+1
-8
@@ -130,7 +130,7 @@ enum StructSoaKind : u8 {
|
||||
|
||||
struct TypeStruct {
|
||||
Slice<Entity *> fields;
|
||||
Slice<String> tags;
|
||||
String * tags; // count == fields.count
|
||||
i64 * offsets; // count == fields.count
|
||||
|
||||
Ast * node;
|
||||
@@ -140,7 +140,6 @@ struct TypeStruct {
|
||||
Type * polymorphic_params; // Type_Tuple
|
||||
Type * polymorphic_parent;
|
||||
|
||||
|
||||
Type * soa_elem;
|
||||
i32 soa_count;
|
||||
StructSoaKind soa_kind;
|
||||
@@ -2174,12 +2173,6 @@ bool are_types_identical(Type *x, Type *y) {
|
||||
if (xf_is_using ^ yf_is_using) {
|
||||
return false;
|
||||
}
|
||||
if (x->Struct.tags.count != y->Struct.tags.count) {
|
||||
return false;
|
||||
}
|
||||
if (x->Struct.tags.count > 0 && x->Struct.tags[i] != y->Struct.tags[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user