aboutsummaryrefslogtreecommitdiff
path: root/stdlib/structs.h
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 /stdlib/structs.h
parentcdda494fe53374dc513b04ada2dc0fad6a8b83bc (diff)
Add optimized metamethods for enums and structs that hold packed data
Diffstat (limited to 'stdlib/structs.h')
-rw-r--r--stdlib/structs.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/stdlib/structs.h b/stdlib/structs.h
index 6553cc86..b027a01e 100644
--- a/stdlib/structs.h
+++ b/stdlib/structs.h
@@ -8,8 +8,10 @@
#include "util.h"
PUREFUNC uint64_t Struct$hash(const void *obj, const TypeInfo_t *type);
+PUREFUNC uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type);
PUREFUNC int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type);
+PUREFUNC bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type);
PUREFUNC bool Struct$is_none(const void *obj, const TypeInfo_t *type);
void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
@@ -25,4 +27,14 @@ void Struct$deserialize(FILE *in, void *outval, Array_t *pointers, const TypeInf
.deserialize=Struct$deserialize, \
})
+#define PackedData$metamethods ((metamethods_t){ \
+ .hash=PackedData$hash, \
+ .compare=Struct$compare, \
+ .equal=PackedData$equal, \
+ .as_text=Struct$as_text, \
+ .is_none=Struct$is_none, \
+ .serialize=Struct$serialize, \
+ .deserialize=Struct$deserialize, \
+})
+
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0