X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/18c831dcd0ae4d660c70ccac69d27ed2a97851be..d23763dae4f649cc29a923298e0232ffdf608744:/struct/darray.c diff --git a/struct/darray.c b/struct/darray.c index aa7e4a2..ed84995 100644 --- a/struct/darray.c +++ b/struct/darray.c @@ -27,13 +27,12 @@ /*----- Header files ------------------------------------------------------*/ -#include #include -#include #include "alloc.h" #include "arena.h" #include "darray.h" +#include "growbuf.h" /*----- Magic numbers -----------------------------------------------------*/ @@ -111,8 +110,8 @@ void *da_ensure(da_base *b, void *v, size_t sz, size_t n) * two which is big enough, starting at double the current size. */ - nsz = v ? b->sz + b->off : (DA_INITSZ >> 1); - do nsz <<= 1; while (nsz < rq); + nsz = b->sz + b->off; + GROWBUF_SIZE(size_t, nsz, rq, DA_INITSZ, sz); /* --- Reallocate the block --- * * @@ -219,8 +218,8 @@ void *da_shunt(da_base *b, void *v, size_t sz, size_t n) * two which is big enough, starting at double the current size. */ - nsz = v ? b->sz + b->off : (DA_INITSZ >> 1); - do nsz <<= 1; while (nsz < rq); + nsz = b->sz + b->off; + GROWBUF_SIZE(size_t, nsz, rq, DA_INITSZ, sz); /* --- Reallocate the block --- * *