nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 20c4811b01dce3946ee30fe13795c67316acda29
parent 721a288c135438335a7a5031f3237612d3213e1a
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Fri,  8 May 2020 20:30:06 +0200

genalloc: unify GEN_ALLOC_readyplus and GEN_ALLOC_ready internals

Introduce an internal static helper function that does the common parts, which
both functions can use.

Diffstat:
Mgen_allocdefs.h | 21++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/gen_allocdefs.h b/gen_allocdefs.h @@ -2,30 +2,25 @@ #define GEN_ALLOC_DEFS_H #define GEN_ALLOC_readyplus(ta,type,field,len,a,i,n,x,base,ta_rplus) \ -int ta_rplus(x,n) register ta *x; register unsigned int n; \ +static int ta_rplus ## _internal (register ta *x, register unsigned int n, unsigned int pluslen) \ { register unsigned int i; \ if (x->field) { \ - i = x->a; n += x->len; \ + i = x->a; n += pluslen; \ if (n > i) { \ x->a = base + n + (n >> 3); \ if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ x->a = i; return 0; } \ return 1; } \ x->len = 0; \ - return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } + return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } \ +int ta_rplus(x,n) register ta *x; register unsigned int n; \ +{ return ta_rplus ## _internal (x, n, x->len); } +/* this needs a GEN_ALLOC_readyplus call before as it reuses the internal helper + * function. */ #define GEN_ALLOC_ready(ta,type,field,len,a,i,n,x,base,ta_ready) \ int ta_ready(x,n) register ta *x; register unsigned int n; \ -{ register unsigned int i; \ - if (x->field) { \ - i = x->a; \ - if (n > i) { \ - x->a = base + n + (n >> 3); \ - if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \ - x->a = i; return 0; } \ - return 1; } \ - x->len = 0; \ - return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } +{ return ta_ready ## plus_internal (x, n, 0); } #define GEN_ALLOC_append(ta,type,field,len,a,i,n,x,base,ta_rplus,ta_append) \ int ta_append(x,i) register ta *x; register type *i; \