X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/c6e5bbae090d043b2e852bb8137bea8e5bca6a6f..dd3c57bc8cac59e0d657ee665ce462988d27d714:/darray.c diff --git a/darray.c b/darray.c index 83150f7..aa7e4a2 100644 --- a/darray.c +++ b/darray.c @@ -1,13 +1,11 @@ /* -*-c-*- - * - * $Id: darray.c,v 1.4 1999/11/06 12:40:45 mdw Exp $ * * Dynamically growing dense arrays * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,35 +13,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: darray.c,v $ - * Revision 1.4 1999/11/06 12:40:45 mdw - * Minor changes to allocation strategy. - * - * Revision 1.3 1999/10/29 22:59:22 mdw - * New array adjustment macros for unsigned arguments. - * - * Revision 1.2 1999/10/28 22:05:28 mdw - * Modify and debug allocation routines. - * - * Revision 1.1 1999/10/22 22:37:26 mdw - * New dynamic array implementation replaces `dynarray.h'. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -51,6 +32,7 @@ #include #include "alloc.h" +#include "arena.h" #include "darray.h" /*----- Magic numbers -----------------------------------------------------*/ @@ -140,14 +122,14 @@ void *da_ensure(da_base *b, void *v, size_t sz, size_t n) */ if (p && slots == b->off) { - q = xrealloc(p - b->off * sz, nsz * sz); + q = x_realloc(b->a, p - b->off * sz, nsz * sz, b->sz + b->off); q += slots * sz; } else { - q = xmalloc(nsz * sz); + q = x_alloc(b->a, nsz * sz); q += slots * sz; if (p) { memcpy(q, p, b->len * sz); - free(p - b->off * sz); + x_free(b->a, p - b->off * sz); } } @@ -246,15 +228,15 @@ void *da_shunt(da_base *b, void *v, size_t sz, size_t n) * almost all the time -- that's the whole point of this routine! */ - q = xmalloc(nsz * sz); + q = x_alloc(b->a, nsz * sz); q += (nsz - slots) * sz; if (p) { memcpy(q, p, b->len * sz); - free(p - b->off * sz); + x_free(b->a, p - b->off * sz); } /* --- Fill in the other parts of the base structure --- */ - + b->off = nsz - slots; b->sz = slots; b->unshift = b->push = 0; @@ -286,13 +268,13 @@ void *da_tidy(da_base *b, void *v, size_t sz) return (p); if (!b->len) { - free(p - b->off * sz); + xfree(p - b->off * sz); return (0); } - q = xmalloc(b->len * sz); + q = x_alloc(b->a, b->len * sz); memcpy(q, p, b->len * sz); - free(p - b->off * sz); + x_free(b->a, p - b->off * sz); b->sz = b->len; b->off = 0; return (q);