aboutsummaryrefslogtreecommitdiff
path: root/teensy/dyn_arr.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-09 17:15:10 -0400
committeriamcheeseman <[email protected]>2026-05-09 17:15:10 -0400
commit9ed5698b3c74c7ce1784d3bebe2aa73d5a0c319d (patch)
treea80df2a06ea9cf3ac2443a2fe683aaa2fdbafab5 /teensy/dyn_arr.c
parentcda8e15a87e46342a268b5da79f53ff53ebf6cbb (diff)
move more of the dynamic array code to be macros
Diffstat (limited to 'teensy/dyn_arr.c')
-rw-r--r--teensy/dyn_arr.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/teensy/dyn_arr.c b/teensy/dyn_arr.c
index 38e3b31..46e619d 100644
--- a/teensy/dyn_arr.c
+++ b/teensy/dyn_arr.c
@@ -3,42 +3,10 @@
#include <stdio.h>
#include <assert.h>
-void *_ty_list_create(size_t type_size, int init_cap)
+void *ty_list_create(void)
{
- init_cap = init_cap < TY_LIST_MIN_CAP
- ? TY_LIST_MIN_CAP
- : init_cap;
-
- int *arr = (int*)ty_alloc(type_size * init_cap + sizeof(int) * 2);
-
- arr[0] = 0;
- arr[1] = init_cap;
- return (void*)(arr + 2);
-}
-
-void *_ty_list_append_slot(size_t type_size, void **arr)
-{
- int *cap = ty_list_cap_ptr(*arr);
- int *len = ty_list_len_ptr(*arr);
-
- (*len)++;
-
- if (*len > *cap) {
- *cap *= TY_LIST_GROW_RATE;
-
- void* base = ty_list_base(*arr);
- base = ty_realloc(base, (type_size * *cap) + sizeof(int) * 2);
- assert(base != NULL); // Just to handle the case
- *arr = (void*)((int*)base + 2);
-
- len = ty_list_len_ptr(*arr);
- }
-
- return (char*)*arr + ((*len - 1) * type_size);
-}
-
-void ty_list_free(void *arr)
-{
- void *base = ty_list_base(arr);
- ty_free(base);
+ struct ty_list_header *header = ty_alloc(sizeof(struct ty_list_header));
+ header->cap = 0;
+ header->len = 0;
+ return (void*)(header + 1);
}