perform full check on bag elements

This commit is contained in:
Jethro Grassie 2020-09-17 21:32:02 -04:00
parent b882424504
commit 91e17d4c58
No known key found for this signature in database
GPG Key ID: DE8ED755616565BB
1 changed files with 13 additions and 3 deletions

View File

@ -86,6 +86,16 @@ gbag_free(gbag_t *gb)
free(gb);
}
static inline int
gbag_occupied(gbag_t *gb, char *el)
{
char *s = el;
char *e = el + gb->z;
while (s < e)
if (*s++) return 1;
return 0;
}
void *
gbag_get(gbag_t *gb)
{
@ -99,7 +109,7 @@ gbag_get(gbag_t *gb)
scan:
while(gb->n < end)
{
if (!*gb->n)
if (!gbag_occupied(gb, gb->n))
{
gb->ref++;
rv = gb->n;
@ -184,7 +194,7 @@ gbag_first(gbag_t *gb)
gb->ni = s;
while (s<e)
{
if (*s)
if (gbag_occupied(gb, s))
return s;
s += gb->z;
gb->ni = s;
@ -202,7 +212,7 @@ gbag_next(gbag_t *gb, void* from)
while (s<e)
{
gb->ni += gb->z;
if (*s)
if (gbag_occupied(gb, s))
return s;
s += gb->z;
}