From fcda36561d668f43bac91ea31cd55cbbd605d330 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 23 Aug 2025 19:28:08 -0400 Subject: Autoformat everything with clang-format --- src/stdlib/structs.c | 85 ++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 52 deletions(-) (limited to 'src/stdlib/structs.c') diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c index 5d6b2319..d2300b74 100644 --- a/src/stdlib/structs.c +++ b/src/stdlib/structs.c @@ -13,13 +13,10 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" #endif -PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) -{ - if (type->StructInfo.num_fields == 0) - return 0; +PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) { + if (type->StructInfo.num_fields == 0) return 0; - if (type->StructInfo.num_fields == 1) - return generic_hash(obj, type->StructInfo.fields[0].type); + if (type->StructInfo.num_fields == 1) return generic_hash(obj, type->StructInfo.fields[0].type); uint64_t field_hashes[type->StructInfo.num_fields]; ptrdiff_t byte_offset = 0; @@ -27,7 +24,7 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; if (field.type == &Bool$info) { - bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1; + bool b = ((*(char *)(obj + byte_offset)) >> bit_offset) & 0x1; field_hashes[i] = (uint32_t)b; bit_offset += 1; if (bit_offset >= 8) { @@ -45,34 +42,29 @@ PUREFUNC public uint64_t Struct$hash(const void *obj, const TypeInfo_t *type) byte_offset += field.type->size; } } - return siphash24((void*)field_hashes, sizeof(field_hashes)); + return siphash24((void *)field_hashes, sizeof(field_hashes)); } #ifdef __GNUC__ #pragma GCC diagnostic pop #endif -PUREFUNC public uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type) -{ - if (type->StructInfo.num_fields == 0) - return 0; +PUREFUNC public uint64_t PackedData$hash(const void *obj, const TypeInfo_t *type) { + if (type->StructInfo.num_fields == 0) return 0; return siphash24(obj, (size_t)type->size); } -PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type) -{ - if (x == y) - return 0; +PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *type) { + if (x == y) return 0; ptrdiff_t byte_offset = 0; ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; if (field.type == &Bool$info) { - bool bx = ((*(char*)(x + byte_offset)) >> bit_offset) & 0x1; - bool by = ((*(char*)(y + byte_offset)) >> bit_offset) & 0x1; - if (bx != by) - return (int32_t)bx - (int32_t)by; + bool bx = ((*(char *)(x + byte_offset)) >> bit_offset) & 0x1; + bool by = ((*(char *)(y + byte_offset)) >> bit_offset) & 0x1; + if (bx != by) return (int32_t)bx - (int32_t)by; bit_offset += 1; if (bit_offset >= 8) { byte_offset += 1; @@ -86,28 +78,24 @@ PUREFUNC public int32_t Struct$compare(const void *x, const void *y, const TypeI if (field.type->align && byte_offset % field.type->align > 0) byte_offset += field.type->align - (byte_offset % field.type->align); int32_t cmp = generic_compare(x + byte_offset, y + byte_offset, field.type); - if (cmp != 0) - return cmp; + if (cmp != 0) return cmp; byte_offset += field.type->size; } } return 0; } -PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type) -{ - if (x == y) - return true; +PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type) { + if (x == y) return true; ptrdiff_t byte_offset = 0; ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; if (field.type == &Bool$info) { - bool bx = ((*(char*)(x + byte_offset)) >> bit_offset) & 0x1; - bool by = ((*(char*)(y + byte_offset)) >> bit_offset) & 0x1; - if (bx != by) - return false; + bool bx = ((*(char *)(x + byte_offset)) >> bit_offset) & 0x1; + bool by = ((*(char *)(y + byte_offset)) >> bit_offset) & 0x1; + if (bx != by) return false; bit_offset += 1; if (bit_offset >= 8) { byte_offset += 1; @@ -120,22 +108,19 @@ PUREFUNC public bool Struct$equal(const void *x, const void *y, const TypeInfo_t } if (field.type->align && byte_offset % field.type->align > 0) byte_offset += field.type->align - (byte_offset % field.type->align); - if (!generic_equal(x + byte_offset, y + byte_offset, field.type)) - return false; + if (!generic_equal(x + byte_offset, y + byte_offset, field.type)) return false; byte_offset += field.type->size; } } return true; } -PUREFUNC public bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type) -{ +PUREFUNC public bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type) { if (x == y) return true; return (memcmp(x, y, (size_t)type->size) == 0); } -PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type) -{ +PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type) { if (!obj) return Text$from_str(type->StructInfo.name); Text_t name = Text$from_str(type->StructInfo.name); @@ -148,15 +133,14 @@ PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const Type ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; - if (i > 0) - text = Text$concat(text, Text(", ")); + if (i > 0) text = Text$concat(text, Text(", ")); - if (type->StructInfo.num_fields > 1) - text = Text$concat(text, Text$from_str(field.name), Text("=")); + if (type->StructInfo.num_fields > 1) text = Text$concat(text, Text$from_str(field.name), Text("=")); if (field.type == &Bool$info) { - bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1; - text = Text$concat(text, Text$from_str(colorize ? (b ? "\x1b[35myes\x1b[m" : "\x1b[35mno\x1b[m") : (b ? "yes" : "no"))); + bool b = ((*(char *)(obj + byte_offset)) >> bit_offset) & 0x1; + text = Text$concat( + text, Text$from_str(colorize ? (b ? "\x1b[35myes\x1b[m" : "\x1b[35mno\x1b[m") : (b ? "yes" : "no"))); bit_offset += 1; if (bit_offset >= 8) { byte_offset += 1; @@ -176,19 +160,16 @@ PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const Type return Text$concat(text, Text(")")); } -PUREFUNC public bool Struct$is_none(const void *obj, const TypeInfo_t *type) -{ - return *(bool*)(obj + type->size); -} +PUREFUNC public bool Struct$is_none(const void *obj, const TypeInfo_t *type) { return *(bool *)(obj + type->size); } -public void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) -{ +public +void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) { ptrdiff_t byte_offset = 0; ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; if (field.type == &Bool$info) { - bool b = ((*(char*)(obj + byte_offset)) >> bit_offset) & 0x1; + bool b = ((*(char *)(obj + byte_offset)) >> bit_offset) & 0x1; fputc((int)b, out); bit_offset += 1; if (bit_offset >= 8) { @@ -208,15 +189,15 @@ public void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, cons } } -public void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type) -{ +public +void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type) { ptrdiff_t byte_offset = 0; ptrdiff_t bit_offset = 0; for (int i = 0; i < type->StructInfo.num_fields; i++) { NamedType_t field = type->StructInfo.fields[i]; if (field.type == &Bool$info) { bool b = (bool)fgetc(in); - *(char*)(outval + byte_offset) |= (b << bit_offset); + *(char *)(outval + byte_offset) |= (b << bit_offset); bit_offset += 1; if (bit_offset >= 8) { byte_offset += 1; -- cgit v1.2.3