From 839c1983a0dad0232da3ceda9c7c02a49715453c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 8 Oct 2024 21:10:36 -0400 Subject: Reduce padding needed for optional types and clean up some redundant type padding --- stdlib/optionals.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'stdlib/optionals.c') diff --git a/stdlib/optionals.c b/stdlib/optionals.c index 37d1b1df..a3b3defc 100644 --- a/stdlib/optionals.c +++ b/stdlib/optionals.c @@ -43,9 +43,13 @@ public PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_typ case TableInfo: return ((Table_t*)obj)->entries.length < 0; case FunctionInfo: return *(void**)obj == NULL; case StructInfo: { - int64_t offset = non_optional_type->size; - if (offset % non_optional_type->align) - offset += non_optional_type->align - (offset % non_optional_type->align); + int64_t offset = 0; + for (int i = 0; i < non_optional_type->StructInfo.num_fields; i++) { + NamedType_t field = non_optional_type->StructInfo.fields[i]; + if (offset > 0 && (offset % field.type->align) > 0) + offset += field.type->align - (offset % field.type->align); + offset += field.type->size; + } return *(bool*)(obj + offset); } case EnumInfo: return (*(int*)obj) == 0; // NULL tag -- cgit v1.2.3