aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-01-08 19:08:34 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-01-08 19:08:34 +0100
commit308f83f0f39886f39400fb79f42a22f853b03327 (patch)
treeb86e41152a78ac7d99d474d5ec9bc271d7c86599
parent036bdc267952fa4e1d484956a37c74f77e75b551 (diff)
Ditch DA_FACTOR
-rw-r--r--da.h12
1 files changed, 3 insertions, 9 deletions
diff --git a/da.h b/da.h
index 1bf8680..1067890 100644
--- a/da.h
+++ b/da.h
@@ -32,10 +32,8 @@
* da_foreach(a, p) Iterate the pointer ‘p’ over each element of the
* array. The type of ‘p’ is inferred.
*
- * The ‘dapush()’ macro will by default double the arrays capacity when it gets
- * full. If you would like to use a different growth factor instead of 2, you
- * can define the DA_FACTOR macro to your desired growth factor before including
- * this file.
+ * The ‘dapush()’ macro will by double the arrays capacity when it gets full.
+ * If you would like your arrays to grow with a different scale, edit this file.
*
*
* Example
@@ -69,10 +67,6 @@
#ifndef MANGO_DA_H
#define MANGO_DA_H
-#ifndef DA_FACTOR
-# define DA_FACTOR 2
-#endif
-
#define __da_s(a) (sizeof(*(a)->buf))
#define dainit(a, n) \
@@ -86,7 +80,7 @@
#define dapush(a, x) \
do { \
if ((a)->len >= (a)->cap) { \
- (a)->cap = (a)->cap * DA_FACTOR + 1; \
+ (a)->cap = (a)->cap ? (a)->cap * 2 : 1; \
if (!((a)->buf = realloc((a)->buf, (a)->cap * __da_s(a)))) \
err(EXIT_FAILURE, "realloc"); \
} \