Important change: ptrArrayAppend() is now implemented in terms of ptrArrayInsertBefore(). ptrArrayInsertBefore() can safely insert at the first invalid index; ValleyBell helped ensure this. tabAppend() will also be implemented this way; boxAppend() might be if uiBoxInsertBefore() becomes a thing. We can rename InsertBefore() to InsertAt() now too.

This commit is contained in:
Pietro Gagliardi 2015-05-18 10:24:51 -04:00
parent ef794a6db5
commit d893102106
1 changed files with 2 additions and 7 deletions

View File

@ -21,17 +21,12 @@ void ptrArrayDestroy(struct ptrArray *p)
void ptrArrayAppend(struct ptrArray *p, void *d) void ptrArrayAppend(struct ptrArray *p, void *d)
{ {
if (p->len >= p->cap) { ptrArrayInsertBefore(p, p->len, d);
p->cap += grow;
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
}
p->ptrs[p->len] = d;
p->len++;
} }
void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d) void ptrArrayInsertBefore(struct ptrArray *p, uintmax_t i, void *d)
{ {
if (i >= p->len) if (i > p->len)
complain("index out of range in ptrArrayInsertBefore()"); complain("index out of range in ptrArrayInsertBefore()");
if (p->len >= p->cap) { if (p->len >= p->cap) {
p->cap += grow; p->cap += grow;