Exemplo n.º 1
0
static inline int adjust_index_rw(strarray_t *sa, int idx, int len)
{
    if (idx >= sa->count) {
	ensure_alloc(sa, idx+len);
    } else if (idx < 0) {
	idx += sa->count;
	if (idx >= 0 && len)
	    ensure_alloc(sa, sa->count+len);
    } else if (len) {
	ensure_alloc(sa, sa->count+len);
    }
    return idx;
}
Exemplo n.º 2
0
/*
 * Like adjust_index_ro(), with extra complication that the function
 * we're performing will expand the array if either the adjusted index
 * points outside the current bounds of the array, or @grow tells us
 * that we're about to need more space in the array.
 */
static inline int adjust_index_rw(strarray_t *sa, int idx, int grow)
{
    if (idx >= sa->count) {
	/* expanding the array as a side effect @idx pointing
	 * outside the current bounds, plus perhaps @grow */
	ensure_alloc(sa, idx+grow);
    } else if (idx < 0) {
	/* adjust Perl-style negative indeces */
	idx += sa->count;
	if (idx >= 0 && grow)
	    ensure_alloc(sa, sa->count+grow);
    } else if (grow) {
	/* expanding the array due to an insert or append */
	ensure_alloc(sa, sa->count+grow);
    }
    return idx;
}