Skip to content

Commit

Permalink
shift out NULL values if possible at remove time (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed May 10, 2024
1 parent b3517b4 commit 6a6a4df
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ udx__fifo_remove (udx_fifo_t *f, void *data, uint32_t pos_hint) {
// check if the pos_hint is correct
if (pos_hint >= f->btm && pos_hint < (f->btm + f->len) && f->values[pos_hint] == data) {
f->values[pos_hint] = NULL;
return;
}

// hint was wrong, do a linear sweep
for (uint32_t i = 0; i < f->len; i++) {
uint32_t j = (f->btm + i) & f->mask;
if (f->values[j] == data) {
f->values[j] = NULL;
return;
} else {
// hint was wrong, do a linear sweep
for (uint32_t i = 0; i < f->len; i++) {
uint32_t j = (f->btm + i) & f->mask;
if (f->values[j] == data) {
f->values[j] = NULL;
break;
}
}
}

while (f->len > 0 && f->values[f->btm] == NULL) udx__fifo_shift(f);
}

0 comments on commit 6a6a4df

Please sign in to comment.