aboutsummaryrefslogtreecommitdiff
path: root/structs.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-12-22 15:53:26 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-12-22 15:53:26 -0500
commit3dd7854076c5f49032ad520dc56769faa1c35d08 (patch)
tree9edc71f9f37b0a667ab0ac5586d34c0089744f21 /structs.c
parentcdda494fe53374dc513b04ada2dc0fad6a8b83bc (diff)
Add optimized metamethods for enums and structs that hold packed data
Diffstat (limited to 'structs.c')
-rw-r--r--structs.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/structs.c b/structs.c
index ce5116e0..8e184266 100644
--- a/structs.c
+++ b/structs.c
@@ -27,10 +27,11 @@ void compile_struct_def(env_t *env, ast_t *ast)
short_name = strrchr(short_name, '$') + 1;
env->code->typeinfos = CORD_all("public const TypeInfo_t ", full_name, ";\n", env->code->typeinfos);
- CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {.size=%zu, .align=%zu, .metamethods=Struct$metamethods, "
+ const char *metamethods = is_packed_data(t) ? "PackedData$metamethods" : "Struct$metamethods";
+ CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {.size=%zu, .align=%zu, .metamethods=%s, "
".tag=StructInfo, .StructInfo.name=\"%s\"%s, "
".StructInfo.num_fields=%ld",
- full_name, type_size(t), type_align(t), short_name, def->secret ? ", .StructInfo.is_secret=true" : "",
+ full_name, type_size(t), type_align(t), metamethods, short_name, def->secret ? ", .StructInfo.is_secret=true" : "",
num_fields);
if (def->fields) {
typeinfo = CORD_asprintf("%r, .StructInfo.fields=(NamedType_t[%d]){", typeinfo, num_fields);