@@@ man wip
[mLib] / struct / darray.c
index aa7e4a2..0b6c223 100644 (file)
@@ -34,6 +34,7 @@
 #include "alloc.h"
 #include "arena.h"
 #include "darray.h"
+#include "growbuf.h"
 
 /*----- Magic numbers -----------------------------------------------------*/
 
@@ -111,8 +112,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(nsz, rq, DA_INITSZ, sz);
 
   /* --- Reallocate the block --- *
    *
@@ -219,8 +220,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(nsz, rq, DA_INITSZ, sz);
 
   /* --- Reallocate the block --- *
    *