diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2017-01-12 22:31:51 -0500 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2017-01-12 22:31:51 -0500 |
commit | 2b4ece6f99c18df090a127ec20c60ff05cbc0705 (patch) | |
tree | e8ef009433b47325520cd6b7f429409cccedce6b /util.c | |
parent | e38da51c14d9eaf8c53b58b3d2e33d7b37768f29 (diff) | |
download | roux-2b4ece6f99c18df090a127ec20c60ff05cbc0705.tar.gz |
use a less obtuse api for vnew()
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/util.c b/util.c index 380f139..9b73771 100644 --- a/util.c +++ b/util.c @@ -6,7 +6,7 @@ typedef struct Vec Vec; struct Vec { ulong mag; - void *(*alloc)(); + Pool pool; size_t esz; ulong cap; union { @@ -119,18 +119,20 @@ icpy(Ins *d, Ins *s, ulong n) } void * -vnew(ulong len, size_t esz, void *alloc(size_t)) +vnew(ulong len, size_t esz, Pool pool) { + void *(*f)(size_t); ulong cap; Vec *v; for (cap=VMin; cap<len; cap*=2) ; - v = alloc(cap * esz + sizeof(Vec)); + f = pool == Pheap ? emalloc : alloc; + v = f(cap * esz + sizeof(Vec)); v->mag = VMag; v->cap = cap; v->esz = esz; - v->alloc = alloc; + v->pool = pool; return v + 1; } @@ -141,7 +143,7 @@ vfree(void *p) v = (Vec *)p - 1; assert(v->mag == VMag); - if (v->alloc == emalloc) { + if (v->pool == Pheap) { v->mag = 0; free(v); } @@ -157,7 +159,7 @@ vgrow(void *vp, ulong len) assert(v+1 && v->mag == VMag); if (v->cap >= len) return; - v1 = vnew(len, v->esz, v->alloc); + v1 = vnew(len, v->esz, v->pool); memcpy(v1, v+1, v->cap * v->esz); vfree(v+1); *(Vec **)vp = v1; |