From 308f83f0f39886f39400fb79f42a22f853b03327 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 8 Jan 2024 19:08:34 +0100 Subject: Ditch DA_FACTOR --- da.h | 12 +++--------- 1 file 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"); \ } \ -- cgit v1.2.3