diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-10-08 21:10:36 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-10-08 21:10:36 -0400 |
| commit | 839c1983a0dad0232da3ceda9c7c02a49715453c (patch) | |
| tree | 955e588981f589b780257c2a8a6fade286f41876 /stdlib/optionals.c | |
| parent | 5103fde1c5e7e92f00801fb3a0e3662e436ee881 (diff) | |
Reduce padding needed for optional types and clean up some redundant
type padding
Diffstat (limited to 'stdlib/optionals.c')
| -rw-r--r-- | stdlib/optionals.c | 10 |
1 files changed, 7 insertions, 3 deletions
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 |
