diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2014-07-10 04:46:13 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2014-07-10 04:46:13 +0200 |
commit | 22648f76ef3d9e8fedf19ee0ea7f476aba144bc3 (patch) | |
tree | ae8fa35f4dd13f511f2f370d0d75553e6ec4afc3 /src/utils | |
parent | e74ec270dd49cb6d980558b0890cdbf3e4c82d6c (diff) | |
download | nanomsg-22648f76ef3d9e8fedf19ee0ea7f476aba144bc3.tar.gz |
Cleanup of nn_queue_remove function.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/queue.c | 53 | ||||
-rw-r--r-- | src/utils/queue.h | 3 |
2 files changed, 23 insertions, 33 deletions
diff --git a/src/utils/queue.c b/src/utils/queue.c index 6a7cd99..069c734 100644 --- a/src/utils/queue.c +++ b/src/utils/queue.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2012 250bpm s.r.o. All rights reserved. + Copyright (c) 2012 250bpm s.r.o. All rights reserv Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -54,37 +54,28 @@ void nn_queue_push (struct nn_queue *self, struct nn_queue_item *item) self->tail = item; } -void nn_queue_maybe_remove (struct nn_queue *self, struct nn_queue_item *item) +void nn_queue_remove (struct nn_queue *self, struct nn_queue_item *item) { - if (item->next == NN_QUEUE_NOTINQUEUE) - return; - - if (self->head == item) { - self->head = self->head->next; - if (!self->head) - self->tail = NULL; - item->next = NN_QUEUE_NOTINQUEUE; - } else { - struct nn_queue_item *prev = self->head; - - while (1) { - if (!prev) break; - - struct nn_queue_item *curr = prev->next; - - if (curr == item) { - prev->next = curr->next; - if (self->tail == curr) - self->tail = prev; - - item->next = NN_QUEUE_NOTINQUEUE; - break; - } - prev = curr; - } - } - - nn_assert (item->next == NN_QUEUE_NOTINQUEUE); + struct nn_queue_item *it; + struct nn_queue_item *prev; + + if (item->next == NN_QUEUE_NOTINQUEUE) + return; + + prev = NULL; + for (it = self->head; it != NULL; it = it->next) { + if (it == item) { + if (self->head == it) + self->head = it->next; + if (self->tail == it) + self->tail = prev; + if (prev) + prev->next = it->next; + item->next = NN_QUEUE_NOTINQUEUE; + return; + } + prev = it; + } } struct nn_queue_item *nn_queue_pop (struct nn_queue *self) diff --git a/src/utils/queue.h b/src/utils/queue.h index 466b22a..caff9b9 100644 --- a/src/utils/queue.h +++ b/src/utils/queue.h @@ -53,8 +53,7 @@ int nn_queue_empty (struct nn_queue *self); void nn_queue_push (struct nn_queue *self, struct nn_queue_item *item); /* Remove the item if it is present in the queue. */ -void nn_queue_maybe_remove (struct nn_queue *self, - struct nn_queue_item *item); +void nn_queue_remove (struct nn_queue *self, struct nn_queue_item *item); /* Retrieves one element from the queue. The element is removed from the queue. Returns NULL if the queue is empty. */ |