aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-11 00:18:36 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-11 00:18:36 +0200
commit7d9c8cb5956cab41492c7b70011d7d637d4d2a4c (patch)
tree44d9767489fc5bd0b018d8e5f16e346661a285c6 /include
parentb04989164df973eaf6565d1c9bf2505215a54604 (diff)
Implement dagrow()
Diffstat (limited to 'include')
-rw-r--r--include/dynarr.h11
1 files changed, 4 insertions, 7 deletions
diff --git a/include/dynarr.h b/include/dynarr.h
index 0a7e2c6..31d1e10 100644
--- a/include/dynarr.h
+++ b/include/dynarr.h
@@ -15,6 +15,7 @@
}
void *daextend(void *, void *, size_t, size_t, size_t);
+void *dagrow(void *, size_t, size_t, size_t);
#define dapush(da, x) \
((typeof((da)->buf))(daextend)((da), (typeof(x)[1]){(x)}, 1, sizeof(x), \
@@ -24,13 +25,9 @@ void *daextend(void *, void *, size_t, size_t, size_t);
((typeof((da)->buf))daextend((da), (xs), (n), sizeof(*(xs)), \
alignof(*(xs))))
-#define DAGROW(da, n) \
- do { \
- if ((n) > (a)->cap) { \
- (a)->cap = (n); \
- (a)->buf = bufalloc((a)->buf, (a)->cap, sizeof(*(a)->buf)); \
- } \
- } while (false)
+#define dagrow(da, n) \
+ ((typeof((da)->buf))dagrow((da), (n), sizeof(*(da)->buf), \
+ alignof(*(da)->buf)))
#define DAEXTEND(da, xs, n) \
do { \