aboutsummaryrefslogtreecommitdiff
path: root/string.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 /string.c
parent88eb8c969f6abe119994c7ab307b9be58ff076a5 (diff)
feat(string): Arena base allocation for copy
Diffstat (limited to 'string.c')
-rw-r--r--string.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/string.c b/string.c
index 191059e..0fc8341 100644
--- a/string.c
+++ b/string.c
@@ -20,11 +20,12 @@ uint64_t Str_hash64(Str s) {
return h;
}
-Str Str_copy(Arena *a, char *data, uintptr_t len) {
- Str str = {.data = NULL, .len = len};
- str.data = new (a, char, len);
- if (str.len)
- memcpy(str.data, data, len);
+Str* Str_copy(Arena *a, char *data, uintptr_t len) {
+ Str *str = new(a, Str, 1);
+ str->len = len;
+ str->data = new (a, char, len);
+ if (str->len)
+ memcpy(str->data, data, len);
return str;
}