diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-17 21:58:31 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-17 21:58:31 -0400 |
| commit | 146d3542d5f626099f4c30a0190b6e1d963e70f4 (patch) | |
| tree | 4d6ae27d2cd6c2147998e193f9591300d58d649d | |
| parent | 212dfa44ae3b99b6953b2096fa27406ca4bba303 (diff) | |
Don't bother comparing empty structs
| -rw-r--r-- | structs.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -152,8 +152,12 @@ void compile_struct_def(env_t *env, ast_t *ast) CORD typeinfo = CORD_asprintf("public const TypeInfo %r = {%zu, %zu, {.tag=CustomInfo, .CustomInfo={", full_name, type_size(t), type_align(t)); - typeinfo = CORD_all(typeinfo, ".as_text=(void*)", full_name, "$as_text, .compare=(void*)", full_name, "$compare, "); - env->code->funcs = CORD_all(env->code->funcs, compile_str_method(env, ast), compile_compare_method(env, ast)); + typeinfo = CORD_all(typeinfo, ".as_text=(void*)", full_name, "$as_text, "); + env->code->funcs = CORD_all(env->code->funcs, compile_str_method(env, ast)); + if (t->tag != StructType || Match(t, StructType)->fields) { + typeinfo = CORD_all(typeinfo, ".compare=(void*)", full_name, "$compare, "); + env->code->funcs = CORD_all(env->code->funcs, compile_compare_method(env, ast)); + } if (!t || !is_plain_data(env, t)) { env->code->funcs = CORD_all( env->code->funcs, compile_equals_method(env, ast), |
