Skip to content

Commit 6a6a4df

Browse files
authored
shift out NULL values if possible at remove time (#183)
1 parent b3517b4 commit 6a6a4df

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/fifo.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ udx__fifo_remove (udx_fifo_t *f, void *data, uint32_t pos_hint) {
7474
// check if the pos_hint is correct
7575
if (pos_hint >= f->btm && pos_hint < (f->btm + f->len) && f->values[pos_hint] == data) {
7676
f->values[pos_hint] = NULL;
77-
return;
78-
}
79-
80-
// hint was wrong, do a linear sweep
81-
for (uint32_t i = 0; i < f->len; i++) {
82-
uint32_t j = (f->btm + i) & f->mask;
83-
if (f->values[j] == data) {
84-
f->values[j] = NULL;
85-
return;
77+
} else {
78+
// hint was wrong, do a linear sweep
79+
for (uint32_t i = 0; i < f->len; i++) {
80+
uint32_t j = (f->btm + i) & f->mask;
81+
if (f->values[j] == data) {
82+
f->values[j] = NULL;
83+
break;
84+
}
8685
}
8786
}
87+
88+
while (f->len > 0 && f->values[f->btm] == NULL) udx__fifo_shift(f);
8889
}

0 commit comments

Comments
 (0)