From 6a6a4dfa2bc6e19fcbb53694524b9fe8bc5f50e5 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Fri, 10 May 2024 17:14:32 +0200 Subject: [PATCH] shift out NULL values if possible at remove time (#183) --- src/fifo.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/fifo.c b/src/fifo.c index 6a0ac60b..e2a71e69 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -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); }