aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-10 23:47:31 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-10 23:47:31 +0200
commitb04989164df973eaf6565d1c9bf2505215a54604 (patch)
tree44d49cc803cc00b534e14a701bca7b8ebce90c2e /include
parent4f62899af7e97501ec081f9268d80ebf87150c2a (diff)
Add daextend() to the new dynarr system
Diffstat (limited to 'include')
-rw-r--r--include/dynarr.h21
1 files changed, 8 insertions, 13 deletions
diff --git a/include/dynarr.h b/include/dynarr.h
index 52cacc5..0a7e2c6 100644
--- a/include/dynarr.h
+++ b/include/dynarr.h
@@ -14,11 +14,15 @@
void *ctx; \
}
-void *dapush(void *, void *, size_t, size_t);
+void *daextend(void *, void *, size_t, size_t, size_t);
-#define dapush(da, ...) \
- dapush((da), ((typeof(__VA_ARGS__)[1]){__VA_ARGS__}), sizeof(__VA_ARGS__), \
- alignof(__VA_ARGS__))
+#define dapush(da, x) \
+ ((typeof((da)->buf))(daextend)((da), (typeof(x)[1]){(x)}, 1, sizeof(x), \
+ alignof(x)))
+
+#define daextend(da, xs, n) \
+ ((typeof((da)->buf))daextend((da), (xs), (n), sizeof(*(xs)), \
+ alignof(*(xs))))
#define DAGROW(da, n) \
do { \
@@ -28,15 +32,6 @@ void *dapush(void *, void *, size_t, size_t);
} \
} while (false)
-#define DAPUSH(da, x) \
- do { \
- if ((da)->len >= (da)->cap) { \
- (da)->cap = (da)->cap ? (da)->cap * 2 : 1; \
- (da)->buf = bufalloc((da)->buf, (da)->cap, sizeof(*(da)->buf)); \
- } \
- (da)->buf[(da)->len++] = (x); \
- } while (false)
-
#define DAEXTEND(da, xs, n) \
do { \
if ((da)->len + (n) >= (da)->cap) { \