From 034d197e7eb3749f9f5b347595abdcfe2d086965 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 23 Jul 2025 14:42:48 +0200 Subject: fix(json): Reduce memory usage and fix memory bugs --- json.h | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'json.h') diff --git a/json.h b/json.h index 99e3e75..60e853c 100644 --- a/json.h +++ b/json.h @@ -9,16 +9,27 @@ typedef struct { Vec values; // Vec size len; } JSONObject; +typedef enum { + JSON_NULL, + JSON_BOOL, + JSON_INTEGER, + JSON_FLOAT, + JSON_STRING, + JSON_ARRAY, + JSON_OBJECT +} JSONType; typedef struct { - i32 *boolean; - i32 *integer; - f32 *floating; - Vec *array; // Vec - Str *string; - void *null; - JSONObject *object; + JSONType type; + union { + bool boolean; + i32 integer; + f32 floating; + Vec array; // Vec + Str string; + JSONObject object; + } as; } JSON; -JSON *JSONObject_get(JSONObject *obj, Str key); +JSON *JSONObject_get(JSONObject obj, Str key); i32 JSON_fprint(FILE *w, JSON json); JSON JSON_parse(Arena *a, byte *src); JSON JSON_Int(Arena *a, i32 val); -- cgit v1.3