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:
parent
ef794a6db5
commit
d893102106
|
@ -21,17 +21,12 @@ void ptrArrayDestroy(struct ptrArray *p)
|
|||
|
||||
void ptrArrayAppend(struct ptrArray *p, void *d)
|
||||
{
|
||||
if (p->len >= p->cap) {
|
||||
p->cap += grow;
|
||||
p->ptrs = (void **) uiRealloc(p->ptrs, p->cap * sizeof (void *), "void *[]");
|
||||
}
|
||||
p->ptrs[p->len] = d;
|
||||
p->len++;
|
||||
ptrArrayInsertBefore(p, p->len, 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()");
|
||||
if (p->len >= p->cap) {
|
||||
p->cap += grow;
|
||||
|
|
Loading…
Reference in New Issue