aboutsummaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 14:37:12 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 14:37:12 +0200
commit780384484cf58939f9413d644ccdd8c40cb82ae5 (patch)
treecedbd921eb07bc4a9e851c07fb312ce792868206 /json.c
parent88eb8c969f6abe119994c7ab307b9be58ff076a5 (diff)
feat(string): Arena base allocation for copy
Diffstat (limited to 'json.c')
-rw-r--r--json.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/json.c b/json.c
index 0ef03a2..f170e3f 100644
--- a/json.c
+++ b/json.c
@@ -69,7 +69,7 @@ parse_array_result parse_array(Arena *a, char *src, uintptr_t pos) {
}
typedef struct {
- Str string;
+ Str *string;
uintptr_t pos;
} parse_string_result;
@@ -81,7 +81,7 @@ parse_string_result parse_string(Arena *a, char *src, uintptr_t pos) {
i++;
}
assert(src[pos + i] == '"');
- Str s = Str_copy(a, &src[pos + 1], i - 1);
+ Str* s = Str_copy(a, &src[pos + 1], i - 1);
return (parse_string_result){s, pos + i + 1};
}
@@ -104,13 +104,13 @@ parse_object_result parse_object(Arena *a, char *src, uintptr_t pos) {
for (;;) {
assert(src[pos] == '"');
parse_string_result str_result = parse_string(a, src, pos);
- Str key = str_result.string;
+ Str *key = str_result.string;
pos = absorb_whitespaces(src, str_result.pos);
assert(src[pos] == ':');
pos = absorb_whitespaces(src, pos+1);
parse_any_result any_result = parse_any(a, src, pos);
object->len++;
- Vec_push(a, &object->keys, &key);
+ Vec_push(a, &object->keys, key);
Vec_push(a, &object->values, any_result.value);
pos = absorb_whitespaces(src, any_result.pos);
if (src[pos] != ',') {break;}
@@ -132,7 +132,7 @@ parse_any_result parse_any(Arena *a, char *src, uintptr_t pos) {
pos = result.pos;
} else if (src[pos] == '"') {
parse_string_result result = parse_string(a, src, pos);
- value->string = &result.string;
+ value->string = result.string;
pos = result.pos;
} else if (src[pos] == '{') {
parse_object_result result = parse_object(a, src, pos);