diff options
Diffstat (limited to 'lib/vector.c')
-rw-r--r-- | lib/vector.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/vector.c b/lib/vector.c index 3fb4cbd9..646f19a5 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -855,32 +855,26 @@ vector_sak(int to_copy, vector to, * Legacy Vector Operations */ -/* This function only returns next empty slot index. It does not mean - the slot's index memory is assigned, please call vector_ensure() - after calling this function. - - Index returned is <= current (logical) end. -*/ +/* Set value to the smallest empty slot. */ int -vector_empty_slot (vector v) +vector_set (vector v, void *val) { vector_index i; - for (i = 0; i < v->end; i++) - if (v->p_items[i] == NULL) - break ; + i = 0 ; + while (1) + { + if (i == v->end) + { + i = vector_extend_by_1(v) ; + break ; + } - return i; -} + if (v->p_items[i] == NULL) + break ; -/* Set value to the smallest empty slot. */ -int -vector_set (vector v, void *val) -{ - vector_index i; - i = vector_empty_slot(v) ; /* NB: i <= v->end */ - if (i == v->end) - i = vector_extend_by_1(v) ; + ++i ; + } ; v->p_items[i] = val; |